Django PG Migrate

1.6.0 · active · verified Sun Apr 12

django-pgmigrate is a Python library that integrates with Django to minimize downtime during PostgreSQL database migrations. It addresses a common issue where long-running transactions can block `python manage.py migrate` operations, causing subsequent queries to queue up. Version 1.6.0 is the current release, and the project is actively maintained with a regular release cadence to support new Django and Python versions. It automatically detects and terminates blocking queries by default, or can be configured to merely show them or set a lock timeout.

Warnings

Install

Imports

Quickstart

After installing the library, add `pgactivity`, `pglock`, and `pgmigrate` to your `INSTALLED_APPS` in `settings.py`. Then, simply run `python manage.py migrate` as you normally would. `django-pgmigrate` will automatically detect and terminate blocking queries by default.

# settings.py
INSTALLED_APPS = [
    # ...
    'pgactivity',
    'pglock',
    'pgmigrate',
    # ...
]

# Terminal
# Run Django migrations as usual. django-pgmigrate will automatically handle blocking queries.
# Note: This example does not connect to a live database or create models.
# It only shows the necessary Django settings and command execution.
# For a full setup, ensure your database settings are configured.
# For example, in a local development environment:
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.postgresql',
#         'NAME': 'mydatabase',
#         'USER': 'myuser',
#         'PASSWORD': 'mypassword',
#         'HOST': 'localhost',
#         'PORT': '5432',
#     }
# }

# After configuring INSTALLED_APPS, simply run your migrations:
# python manage.py migrate

view raw JSON →