Lesson 2 of 14

Logical Replication and Logical Decoding

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source

The one thing to understand first

Where physical replication ships raw WAL blocks, logical replication ships logical row changes — “insert this row”, “update that row” — reconstructed from the WAL by logical decoding. Because it operates at the row level via SQL, publisher and subscriber can differ in major version, architecture, and even schema, and you can replicate a subset of tables. This flexibility powers upgrades, selective data distribution, and integration pipelines.

Logical replication is not a copy of the database — it is a stream of row-level changes applied by a normal writable backend. That single fact explains every difference: cross-version, partial, conflict-prone, and DDL-blind.

Logical decoding: turning WAL into changes

The WAL was designed for physical recovery, not human-readable changes. Logical decoding (src/backend/replication/logical/) reads the WAL and, using catalog information, reconstructs each committed transaction as an ordered stream of row changes. An output plugin formats that stream; the built-in pgoutput plugin feeds native logical replication, while plugins like wal2json emit JSON for change-data-capture (CDC) consumers.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • Publications and subscriptions
  • Replica identity: how UPDATE/DELETE find rows
  • What it does and does not replicate
  • Conflicts on the subscriber
  • Layer 3 — Watch it happen on your own database
  • Layer 4 — The levers this hands you
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Was this helpful?

← Back to 04 — Advanced: Replication & HA Architecture