Package: pg-logical-manager
pg-logical-managerManage 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 after replica promotion.Pg Logical Manager DemoSetupPypi (production)Simplypip install pglogicalmanager.Virtual environment (development)pip install virtualenvvirtualenv venv --python=python3source .venv/bin/activatepip install -e ".[dev]"When developing inside the virtual environment, use$python-mpglogicalmanagerinstead of$pglogicalmanagerfor all commands.Configuration$pglogicalmanager--source=postgres://user:password@primary-db:5432/database--destination=postgres://user:password@replica-db:5432/databaseThis will write a.envfile in the same current folder. It will contain the DSNs above.Make sure it works$pglogicalmanagerlist-subscriptionsUsageCheck out the help menu:$pglogicalmanager--helpFeaturesBasic featuresYou 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) featuresLogical 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:rewind subscription to specific LSN,reverse subscriptions,manually create/drop replication slots.Rewind subscriptionRewinding a subscription makes it replicate from a paritcular point-in-time. This works likepg_rewindexcept 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.$pglogicalmanagerlist-replication-origins
$pglogicalmanagerrewind-replication-origin--helpTODO: Document use cases.Reverse subscriptionReversing 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.$pglogicalmanagerreverse-subscription--helpThis will also overwrite your.envconfiguration and change the source DSN to the destination DSN and vice versa.Manually creating replication slotsCreating 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!$pglogicalmanagercreate-replication-slottest_slotand see all current replication slots with$pglogicalmanagerlist-replication-slotsTODO: Document use cases.