View and manage logical subscriptions for a PostgreSQL cluster.
Project description
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:
- rewinding subscriptions, i.e. moving back and forth between LSNs,
- creating reverse subscriptions, i.e. send data from replica to primary instead; this is useful when the replica is promoted to primary and the primary should be kept up-to-date in case you want to switch them back.
Setup
Virtual environment (recommended)
pip install virtualenv
virtualenv venv --python=python3
source .venv/bin/activate
pip install -r requirements.txt
Configuration
$ python manager.py configure --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 folder as manager.py
. It will contain the DSNs above.
Make sure it works
$ python manager.py list-subscriptions
Usage
Check out the help menu:
$ python manager.py --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. Two features we found useful and which are implemented here are:
- rewind subscription to specific LSN,
- reverse subscriptions.
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.
$ python manager.py list-replication-origins
$ python manager.py 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.
$ python manager.py reverse-subscription --help
This will also overwrite your .env
configuration and change the source DSN to the destination DSN and vice versa.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pg_logical_manager-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1fed2d559650364bfc06aec37a54b6fed688bc89ad06244b2510dbd36808898 |
|
MD5 | 369002421daff5fc4c841f378e92e393 |
|
BLAKE2b-256 | 2bc29ea08a60d0b58f2483807ed5958414265edc73c70b81f88fdd4d5533623d |