django-pgmigrate
Avoid costly downtime during Postgres migrations.
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-pgmigrateuv
uv add django-pgmigratepoetry
poetry add django-pgmigrateInstalling 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
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-pg-zero-downtime-migrationsProvides a Django database backend for…
permissive · top 15,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI
django-safemigrateAdds a safemigrate command to Django that…
permissive · top 15,000 on PyPI
django-pg-migration-toolsProvides safer, production-ready Django…
permissive · top 15,000 on PyPI
django-linear-migrationsEnforces linear migration history in Django…
permissive · top 5,000 on PyPI
django-read-onlyPrevents Django database write operations by…
permissive · top 15,000 on PyPI
django-pgactivityProvides Django management commands and…
permissive · top 5,000 on PyPI
squawk-cliLinter that analyzes PostgreSQL migrations and…
permissive · top 15,000 on PyPI
django-migration-linterAnalyzes Django migrations to detect…
permissive · top 5,000 on PyPI
django-sequencesProvides gapless sequence generation for Django…
permissive · top 15,000 on PyPI