django-pg-zero-downtime-migrations
Django postgresql backend that apply migrations with respect to database locks
What it is and what it does
django-pg-zero-downtime-migrations is a custom Django database backend for PostgreSQL that replaces the standard backend to apply schema migrations while respecting database-level locks. Instead of using transactions for all migrations (which can cause table locks and downtime), it applies schema changes and SQL operations in a way that minimizes lock contention and allows the application to remain available during deployment.
The package works by managing PostgreSQL's table-level locks—ACCESS EXCLUSIVE, SHARE UPDATE EXCLUSIVE, and others—and applying configurable timeouts to prevent long-running operations from blocking application queries. It requires careful deployment orchestration: migrations are applied first, then application instances are restarted one at a time behind a load balancer to ensure the old and new application versions both work with the new schema. The package is in beta and does not apply zero-downtime guarantees to RunPython operations, only to schema and RunSQL migrations.
Use it for:
- Deploying schema changes to a live PostgreSQL database serving multiple application instances without taking the application offline.
- Adding or modifying columns and indexes on large tables where standard Django migrations would cause extended lock times.
- Recovering from partial migration failures by re-running failed migrations in idempotent mode after fixing underlying data issues.
- Enforcing safe migration practices by raising errors on potentially unsafe operations when ZERO_DOWNTIME_MIGRATIONS_RAISE_FOR_UNSAFE is enabled.
- Managing long-running operations like index creation or constraint validation without triggering global statement timeouts.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a Django database backend for PostgreSQL that executes migrations while minimizing table locks, enabling schema changes without application downtime.
Yes, with conditions. Install this if you need zero-downtime schema migrations on PostgreSQL and can follow the deployment flow (apply migrations, then restart instances one at a time). The package is mature enough for production use (MIT licensed, actively maintained, 573 stars) but remains in beta—test all migrations thoroughly before production deployment. Not suitable if your migrations rely heavily on RunPython operations or if you cannot orchestrate instance restarts behind a load balancer.
Install
django-pg-zero-downtime-migrations on PyPI
pip
pip install django-pg-zero-downtime-migrationsuv
uv add django-pg-zero-downtime-migrationspoetry
poetry add django-pg-zero-downtime-migrationsInstalling django-pg-zero-downtime-migrations
Before you install
Low friction installation with a single dependency on django. The package is marked beta and aging (434 days since release), but the repository remains active with recent commits and moderate community adoption (573 stars). Suitable for production use with careful testing of migrations before deployment.
License in practice
MIT license is permissive and imposes no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
pip install django-pg-zero-downtime-migrations
In settings.py:
DATABASES = {
'default': {
'ENGINE': 'django_zero_downtime_migrations.backends.postgres',
...
}
}
ZERO_DOWNTIME_MIGRATIONS_LOCK_TIMEOUT = '2s'
ZERO_DOWNTIME_MIGRATIONS_STATEMENT_TIMEOUT = '2s'
ZERO_DOWNTIME_MIGRATIONS_RAISE_FOR_UNSAFE = True
Requires PostgreSQL database; does not apply zero-downtime guarantees to RunPython operations, only schema and RunSQL migrations. Migrations are not wrapped in transactions, so partial failures require manual database state recovery.
Verify before relying
- Whether idempotent mode (ZERO_DOWNTIME_MIGRATIONS_IDEMPOTENT_SQL) is suitable for production CI pipelines given its reliance on name and constraint state checks rather than full transaction semantics.
- Performance impact of explicit constraint dropping (ZERO_DOWNTIME_MIGRATIONS_EXPLICIT_CONSTRAINTS_DROP) on large tables with many foreign keys.
- Compatibility with PgBouncer transaction pool mode and whether session pool mode is required for timeout settings to function correctly.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | aging — 434 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 263,718/month — #8,351 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_pg_zero_downtime_migrations-0.19-py3-none-any.whl
Keywords: django, postgres, postgresql, migrations
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-migration-toolsProvides safer, production-ready Django…
permissive · top 15,000 on PyPI
django-pgmigratePrevents migration downtime by detecting and…
permissive · top 5,000 on PyPI
django-postgres-extraExtends Django's ORM to expose…
permissive · top 15,000 on PyPI
migramigra compares PostgreSQL database schemas and…
permissive · top 15,000 on PyPI
squawk-cliLinter that analyzes PostgreSQL migrations and…
permissive · top 15,000 on PyPI
django-syzygyAutomates Django database migration deployment…
permissive · top 15,000 on PyPI
django-pglocksProvides PostgreSQL advisory locks for Django…
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
yoyo-migrationsYoyo-migrations is a database schema migration…
permissive · top 15,000 on PyPI