Skip to main content

django-postgres-hot-upgrade

Deployed to PyPI Deployed to PyPI Continuous Integration MIT License Contributor Covenant

Let Django clear its PostgreSQL extensions OIDs cache, making it possible to update the PostgreSQL version to a new major version on the fly.

The how

$ pip install django-postgres-hot-upgrade
INSTALLED_APPS = [
    ...,
    # Warning: django_postgres_hot_upgrade requires to be placed before
    # django.contrib.postgres otherwise it will not work.
    'django_postgres_hot_upgrade',
    'django.contrib.postgres',
    ...,
]

The why

PostgreSQL keeps internal ids of for various objects (OIDs). This includes loaded extentions. In order to interact with those extensions, Django needs to know these IODs, so it loads them and, in order to avoid unneeded requests, it caches them in memory for the duration of the process.

Several PostgreSQL servers running the same version of PostgreSQL will have consistent OIDs but when you upgrade, OIDs can change. If one uses a PostgreSQL load balancer such as pgbouncer or pgpool, one could be tempted to migrate between major PostgreSQL versions on the fly, avoinding downtime. Indeed, for sufficiently recent versions of PostgreSQL, this would work, apart from the OID problem: if OIDs change, Django needs to update its cache.

django_postgres_hot_upgrade memorizes the postgres version of the server after each connection. When the version is updated, it clears the internal Django OIDs cache, forcing Django to fetch the new values.

The rest

Compatibility: Please refer to versions of Python and Django tested in tox.ini.

License: MIT

Code of Conduct: This project is placed under the Contributor Coveneant. Please report any abuse to joachim.jablon at people-doc.com.

[Maintainers] The ugly part

Apart from its unit tests, this package has an integration test. In order to test the feature, we need to simulate a change of OIDs caused by a live update from PG10 to PG12 in a controlled CI environment. This is the most fragile part of the lib, and the most likely to break in the future. Here's what you need to know:

  • docker-compose.yml define two databases postgres10 and postgres12 listening on 5432 and 5433 respectively.
  • tests/django_settings.py define a default database using libpq envvars. Note that in the settings, we requests the tests to run on the normal database instead of dedicated test_<foo> database.
  • The OIDs are created by Postgres when installing the extensions. This happens in tests/migrations/0001_initial.py. The DJANGO_REVERSE_OPERATIONS env var controls the order of the 2 extensions creation. Running the PG10 migration in normal order and the PG12 migration in reverse order ensures the OIDs will be different.
  • The runtests script ensure the migrations run on both databases in the decided order, then launches the test. Without this, the integration test would likely fail because the OIDs would be the same in the two databases.
  • tox calls runtests.
  • GitHub Actions call tox.

The following work to launch tests locally:

  • run tox or runtests on fresh databases
  • run pytests if you know the OIDs are already properly set on the 2 databases

Release files for django-postgres-hot-upgrade 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-postgres-hot-upgrade 1.1.0
File Size Uploaded
django-postgres-hot-upgrade-1.1.0.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-postgres-hot-upgrade 1.1.0
File Interpreter ABI Platform
django_postgres_hot_upgrade-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / django-postgres-hot-upgrade-1.1.0.tar.gz

Download URL django-postgres-hot-upgrade-1.1.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cdf511e286273ccf3a537099c0f1a8c54b2b800b977f56fb8ec1b017d597595f
BLAKE2b-256 checksum
How to use checksums
c404f180cf9343e5a610d53b294744602580d3d00319ecae9b5c131033b53933
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.6

Release files / django_postgres_hot_upgrade-1.1.0-py3-none-any.whl

Download URL django_postgres_hot_upgrade-1.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9216705016e23feb2c7fecffbf729fb03f2bb051daf95ea5136a3c28d65a1f4
BLAKE2b-256 checksum
How to use checksums
81aa015ae781d202655e1f1daeeca547512884d72b74d3dd66f917b4c85a4fd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page