Skip to main content

Build Status

pg-logical-manager

Manage logical replication for your PostgreSQL cluster. Simply create/drop/enable/disable/list subscriptions.

Includes other more risky but interesting abilities like:

  1. rewinding subscriptions, i.e. moving back and forth between LSNs,
  2. creating reverse subscriptions, i.e. send data from replica to primary instead after replica promotion.

Pg Logical Manager Demo

Setup

Pypi (production)

Simply pip install pglogicalmanager.

Virtual environment (development)

  1. pip install virtualenv
  2. virtualenv venv --python=python3
  3. source .venv/bin/activate
  4. pip install -e ".[dev]"

When developing inside the virtual environment, use

$ python -m pglogicalmanager

instead of

$ pglogicalmanager

for all commands.

Configuration

$ pglogicalmanager --source=postgres://user:password@primary-db:5432/database --destination=postgres://user:password@replica-db:5432/database

This will write a .env file in the same current folder. It will contain the DSNs above.

Make sure it works

$ pglogicalmanager list-subscriptions

Usage

Check out the help menu:

$ pglogicalmanager --help

Features

Basic features

You can easily list, create, drop, disable, and enable subscriptions. These sit directly on top of Postgres primitives (i.e. CREATE SUBSCRIPTION, DROP SUBSCRIPTION, etc.) and are fairly well-known. You can also list tables in source/destination and list columns in those tables.

Advanced (read risky) features

Logical replication is powerful and flexible, and it allows you to do things binary replication can't do. Features we found useful and which are implemented here are:

  1. rewind subscription to specific LSN,
  2. reverse subscriptions,
  3. manually create/drop replication slots.

Rewind subscription

Rewinding a subscription makes it replicate from a paritcular point-in-time. This works like pg_rewind except on a live cluster and without changing the WAL timeline. Note: this is pretty dangerous. If you rewind it to a wrong spot, you could create conflicts (unique contraint violations, for example) and the replication can break.

$ pglogicalmanager list-replication-origins
$ pglogicalmanager rewind-replication-origin --help

TODO: Document use cases.

Reverse subscription

Reversing a subscription is switching roles between the primary and the replica: the replica becomes the primary and the primary becomes the replica. This makes sense if you are promoting the replica to become the new primary and you want the old primary to be kept around for backup/rollback purposes. This is not as risky as rewinding, but it is irreverisble: once done, the replica must be the source for all writes, otherwise a split brain situation will be created.

$ pglogicalmanager reverse-subscription --help

This will also overwrite your .env configuration and change the source DSN to the destination DSN and vice versa.

Manually creating replication slots

Creating replication slots is useful to tell your source (primary) to preserve WAL segments from the point of creation of the slot. The inheritent danger is running out of space on write-heavy systems, since WAL segments won't be cleaned up, and busy servers write a lot of WAL!

$ pglogicalmanager create-replication-slot test_slot

and see all current replication slots with

$ pglogicalmanager list-replication-slots

TODO: Document use cases.

Metadata

Release files for pg-logical-manager 0.4.3

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

Source distribution (sdist)

Source distribution for pg-logical-manager 0.4.3
File Size Uploaded Provenance Actions
pg-logical-manager-0.4.3.tar.gz 9.2 kB Without provenance Details for pg-logical-manager-0.4.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pg-logical-manager 0.4.3
File Interpreter ABI Platform Actions
pg_logical_manager-0.4.3-py3-none-any.whl Python 3 none any Details for pg_logical_manager-0.4.3-py3-none-any.whl

Total release size: 30.8 kB

Release files / pg-logical-manager-0.4.3.tar.gz

Download URL pg-logical-manager-0.4.3.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
54b200a14d9a87e4938c80548fb5880abe2c2ff0a97657f789e594229e71ab63
BLAKE2b-256 checksum
How to use checksums
c6ac5163567e1bd2719135c64c8930efb2c2e25a4a3d6bbd4ee0b20d71fee047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

Release files / pg_logical_manager-0.4.3-py3-none-any.whl

Download URL pg_logical_manager-0.4.3-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8a0963ef5fde5e5a87a631803593d17c1c17982cd59c30a2ca0eae551f7fcae
BLAKE2b-256 checksum
How to use checksums
ce42a83d7eaf5d38d3dbd70cf72db78a50b7c5a7f2d7ca62078c2a28214cd2a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

Security for pg-logical-manager 0.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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