Metadata-Version: 2.1
Name: django-pgmigrate
Version: 1.0.0
Summary: Less downtime during migrations.
Home-page: https://github.com/Opus10/django-pgmigrate
License: BSD-3-Clause
Author: Opus 10 Engineering
Requires-Python: >=3.7.0,<4
Classifier: Framework :: Django
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: django (>=2)
Requires-Dist: django-pglock (<2)
Requires-Dist: importlib_metadata (>=4); python_version >= "3.7" and python_version < "3.8"
Project-URL: Documentation, https://django-pgmigrate.readthedocs.io
Project-URL: Repository, https://github.com/Opus10/django-pgmigrate
Description-Content-Type: text/x-rst

django-pgmigrate
################

``django-pgmigrate`` helps you avoid costly downtime with Postgres migrations.

Imagine the following happens:

1. A long-running task queries a model in a transaction and keeps the transaction open.
2. ``python manage.py migrate`` tries to change a field on the model.

Because of how Postgres queues locks, this common scenario causes **every**
subsequent query on the model to block until the query from 1) has finished.

``django-pgmigrate`` provides the following features to alleviate problematic locking
scenarios when running migrations:

* Detect blocking queries and terminate them automatically (the default behavior).
* Print blocking queries so that you can inspect
  and terminate them manually.
* Set the lock timeout so that migrations are terminated if they block too long.

Installation
============

Install django-pgmigrate with::

    pip3 install django-pgmigrate

After this, add ``pgactivity``, ``pglock``, and ``pgmigrate`` to the ``INSTALLED_APPS``
setting of your Django project.

Quick Start
===========

After following the installation instructions, running
``python manage.py migrate`` will automatically terminate any blocking
queries. Here's an example of what it looks like:

.. image:: docs/static/terminate_blocking.png

There are two additional outputs in the ``migrate`` command versus the original:

1. The first output line shows the Postgres process ID. This is useful for
   querying activity that's blocking the process.
2. The yellow text shows when a blocking query was detected and terminated.
   In our case, it was blocking auth migration 12.

You can configure ``django-pgmigrate`` to show blocked queries instead of automatically
killing them, and you can also set the lock timeout to automatically cancel migrations if
they block for too long.
See the documentation section below for more details.

Compatibility
=============

``django-pgmigrate`` is compatible with Python 3.7 - 3.10, Django 2.2 - 4.1, and Postgres 10 - 15.


Documentation
=============

`View the django-pgmigrate docs here
<https://django-pgmigrate.readthedocs.io/>`_ to learn more about:

* How blocking queries are automatically terminated.
* Configuring the command to show blocking activity instead of terminating it, along
  with instructions on how to manually view and terminate activity.
* Configuring lock timeouts to automatically stop migrations if they block for too long.
* Advanced usage such as creating custom actions to run when queries are blocked.

Contributing Guide
==================

For information on setting up django-pgmigrate for development and
contributing changes, view `CONTRIBUTING.rst <CONTRIBUTING.rst>`_.

Primary Authors
===============

- `Wes Kendall <https://github.com/wesleykendall>`__
- `Paul Gilmartin <https://github.com/PaulGilmartin>`__

