← Lessons

quiz vs the machine

Gold1440

Databases

Logical Replication

Streaming row level changes by publication and subscription for selective, cross version copies.

6 min read · core · beat Gold to climb

Replicating meaning not bytes

Logical replication copies changes as logical row operations rather than raw disk blocks. The source decodes its write ahead log into insert, update, and delete events and ships them to subscribers.

Publications and subscriptions

The model has two sides:

  • A publication on the source declares which tables and which operations to publish.
  • A subscription on the target connects to that publication and applies the changes into matching tables.

Because changes are logical, the subscriber can run a different major version, have extra tables, or carry its own indexes. You can replicate a subset of tables rather than the whole cluster.

What it enables

  • Selective replication of only the tables you care about.
  • Major version upgrades with near zero downtime by replicating into a newer cluster.
  • Consolidating several databases into one reporting target.

Limits to know

  • It does not replicate schema changes, sequences advancing, or large objects automatically.
  • The publisher needs a replication slot so unconsumed changes are retained, which can grow the log if a subscriber falls behind.

Key idea

Logical replication decodes the write ahead log into row level events that a publication exposes and a subscription applies, enabling selective, cross version copies that physical replication cannot do.

Check yourself

Answer to earn rating on the learn ladder.

1. What does logical replication ship to subscribers?

2. Why can a logical subscriber run a different major version?

3. What does a publisher need so unconsumed changes are retained?