skillfed

django-pgmigrate

Avoid costly downtime during Postgres migrations.

django-pgmigrate v1.6.0 989.6K downloads/30d#4,566 on PyPI28
Permissive license BSD-3-Clause AGING released

What it is and what it does

django-pgmigrate is a Django management command wrapper that solves a common Postgres migration problem: when long-running transactions hold locks, subsequent migrations queue behind them and block all queries on the affected model. The package detects these blocking queries and either terminates them automatically (the default) or prints them for manual review. It also supports setting lock timeouts to cancel migrations that block too long.

The package integrates into Django's standard migrate command and requires adding three apps to INSTALLED_APPS. It works with Django 4.2–6.0, Python 3.10–3.14, and Postgres 14–18, making it compatible with modern Django deployments. The two runtime dependencies are django and django-pglock.

Use it for:

  • Automatically terminate blocking queries during production migrations to prevent cascading locks.
  • Inspect and manually manage blocking activity instead of auto-terminating for workloads requiring careful query control.
  • Set lock timeouts to fail fast if a migration blocks longer than a configured threshold.
  • Monitor Postgres process IDs during migrations to correlate blocking activity with application logs.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Prevents migration downtime by detecting and terminating blocking queries during Postgres migrations, or optionally showing them for manual inspection.

Yes, if you run Django on Postgres and want to reduce migration downtime. The package is straightforward to install, has no security vulnerabilities, and solves a real operational problem. The aging maintenance status is a minor concern but not a blocker—the codebase is stable and compatible with current versions. Install it if migration locking is a pain point; skip it if you use other databases or have short, non-blocking migrations.

Install

django-pgmigrate on PyPI

pip

pip install django-pgmigrate

uv

uv add django-pgmigrate

poetry

poetry add django-pgmigrate

Installing django-pgmigrate

Before you install

Low friction install with a pure Python wheel. Maintenance status is aging—last commit was 2025-11-30 and the project has 28 stars—but the package remains actively maintained and compatible with current Django and Python versions.

License in practice

BSD-3-Clause is permissive and poses no restriction on commercial or private use.

Quickstart

pip install django-pgmigrate

# Add to Django INSTALLED_APPS:
# 'pgactivity', 'pglock', 'pgmigrate'

python manage.py migrate

Requires Django 4.2–6.0, Python 3.10–3.14, Postgres 14–18, and Psycopg 2–3.

Verify before relying

  • Whether automatic query termination is safe for all workload types or if manual inspection is recommended in production.
  • Performance impact of blocking-query detection during large migration batches.

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (<4,>=3.10.0)
Install friction low — pure-Python wheel
Runtime dependencies 2 — django, django-pglock
Maintenance aging — 257 days since the last release
Last repo commit
First released
Downloads 989,583/month — #4,566 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_pgmigrate-1.6.0-py3-none-any.whl

Framework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

postgres migration lockingdjango migration blocking queriesavoid migration downtimepostgres lock timeoutdjango database migration safety
django-opspostgres-migrations

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

django-pg-zero-downtime-migrations

Provides a Django database backend for…

permissive · top 15,000 on PyPI

django-pglock

Provides Postgres advisory locks, table locks,…

permissive · top 5,000 on PyPI

django-safemigrate

Adds a safemigrate command to Django that…

permissive · top 15,000 on PyPI

django-pg-migration-tools

Provides safer, production-ready Django…

permissive · top 15,000 on PyPI

django-linear-migrations

Enforces linear migration history in Django…

permissive · top 5,000 on PyPI

django-read-only

Prevents Django database write operations by…

permissive · top 15,000 on PyPI

django-pgactivity

Provides Django management commands and…

permissive · top 5,000 on PyPI

squawk-cli

Linter that analyzes PostgreSQL migrations and…

permissive · top 15,000 on PyPI

django-migration-linter

Analyzes Django migrations to detect…

permissive · top 5,000 on PyPI

django-sequences

Provides gapless sequence generation for Django…

permissive · top 15,000 on PyPI