- Table specific replicatlion
- Support on postgres 10 above
- Pub-sub model
- Also known as Change Data Capture (CDC)
-
Logical Replication
- by replication identity (Primary Key)
- Publisher - subscriber relationship
-
Physcal Replicaton
- Physical by WAL/bytes
- Master - Slave relationship
- Cross Version Support
- Flexible (Row filtering, column filtering, data transformation)
- Lighweight (compare other replication type)
- Only DML operations are supported. No DDL. The schema has to be defined beforehand
- Sequences are not replicated
- Large Objects are not replicated
- Only plain base tables are supported (materialized views, partition root tables, foreign tables are not supported)
- Data Conflict can be problem
- Conflict halt the replication
- Can caused publisher out of disk
- Slot Failover learn more
Not support logical replication from a REPLICA/SLAVE. learn more--> Usepg_replication_slot_advance
- Sending incremental changes in a single database or a subset of a database to subscribers as they occur.
- Firing triggers for individual changes as they arrive on the subscriber.
- Consolidating multiple databases into a single one (for example for analytical purposes).
- Replicating between different major versions of PostgreSQL.
- Replicating between PostgreSQL instances on different platforms (for example Linux to Windows)
- Giving access to replicated data to different groups of users.
- Sharing a subset of the database between multiple databases.
pglogical
: https://github.com/2ndQuadrant/pglogical
max_wal_senders
max_replication_slots
pg_catalog.pg_publication
pg_catalog.pg_publication_tables
pg_current_wal_lsn()
pg_stat_replication
pg_stat_subscription
pg_replication_slots
Learn more:
- https://dba.stackexchange.com/questions/224490/using-postgresql-logical-replication-how-do-you-know-that-the-subscriber-is-cau
- https://shipt.tech/monitoring-postgres-logical-replication-12e54599d16a
CREATE PUBLICATION my_publication FOR TABLE replicate_me WITH (publish = 'insert');
CREATE SUBSCRIPTION my_sub
CONNECTION 'host=172.168.18.50 port=5432 user=repl dbname=testdb'
PUBLICATION my_publication;
- https://www.postgresql.org/docs/current/logical-replication.html
- https://aws.amazon.com/blogs/database/using-logical-replication-to-replicate-managed-amazon-rds-for-postgresql-and-amazon-aurora-to-self-managed-postgresql/
- https://cloud.google.com/sql/docs/postgres/replication/configure-logical-replication
- https://severalnines.com/blog/using-postgresql-logical-replication-maintain-always-date-readwrite-test-server/
- https://www.postgresql.eu/events/pgconfde2022/sessions/session/3745/slides/306/Implementing%20failover%20of%20logical%20replication%20slots%20in%20Patroni.pdf