5
Publication and Subscription
Publication
includes one or more database tables
can specify columns and row filters
processes INSERT, UPDATE, DELETE, TRUNCATE commands
sends row-level changes after transaction commit
uses a logical replication slot
Subscription
receives and applies changes
can do initial synchronization
no parsing, rewriting and planning, just direct execution
possible conflicts with local data
Logical replication uses a publish and subscribe model.
A publication is created on one server and can include several tables in a
single database. Starting with version 15, PostgreSQL allows publishing
partial table data by specifying column subsets and row filter conditions.
Other servers can subscribe to this publication to receive and apply changes
to the tables.
Only table row modifications are replicated (not SQL commands). DDL
commands are not transmitted, so target tables on the subscriber must be
created manually. Initial synchronization of table contents can be performed
when a subscription is created.
After transaction commit, information about modified rows is extracted from
WAL records on the publisher through logical decoding. The resulting
messages are transmitted to subscribers via the replication protocol in a
platform- and version-independent format.
Changes are applied without executing SQL commands, avoiding parsing
and planning overhead. On the other hand, a single SQL command can
result in multiple one-row changes.