Skip to main content
RunBook Academy

PostgreSQLXIV · Replication, Slots and Read ReplicasReplication

Physical streaming replication end to end

Intermediate⏱ ~30 minpsql

What you'll learn

  • Describe the path a change takes from primary commit to standby visibility
  • Name the processes involved on each side
  • Explain why physical replication is all-or-nothing
  • State what physical replication can and cannot be used for

Prerequisites

Verified against PostgreSQL 18.x · PostgreSQL (comparison targets) 17.11, 16.15 · PostgreSQL (support calendar) 18, 17, 16, 15, 14 supported · pgBackRest 2.59.1 · PgBouncer 1.25.2 · Patroni 4.1.5 · Ubuntu (host baseline) 26.04 LTS · 2026-08-27

Not yet marked complete on this device.

Part XII established that WAL is the record of every change, and that crash recovery is replaying it. Replication is the same replay, on a different machine, that never stops.

The path a change takes

  1. A backend on the primary modifies a page and writes a WAL record.
  2. COMMIT flushes WAL to disk on the primary. The commit is now durable locally and, by default, returns to the client here.
  3. The walsender reads that WAL and sends it over a replication connection.
  4. The walreceiver on the standby receives it and writes it.
  5. The walreceiver flushes it to the standby’s disk.
  6. The startup process on the standby replays it into the standby’s pages.
  7. The change becomes visible to queries on the standby.

Steps 3 to 7 happen after the client was told the commit succeeded, unless you configure otherwise. That gap is the subject of lessons XIV-04 and XIV-05.

The processes

Read-only / Safethe primary, with one standby connected
$ ps -eo pid,args | grep postgres:
     71 postgres: checkpointer
   72 postgres: background writer
   74 postgres: walwriter
   75 postgres: autovacuum launcher
   76 postgres: logical replication launcher
  124 postgres: walsender repl 172.26.0.3(46864) streaming 0/5000060
Read-only / Safethe standby
$ ps -eo pid,args | grep postgres:
     31 postgres: startup recovering 000000010000000000000005
   32 postgres: walreceiver streaming 0/5000060

Two processes carry the mechanism. One walsender per connected standby, one walreceiver per standby.

What “physical” means

Physical replication ships byte-level changes to pages. Record 47 says “on relation 16384, block 219, at offset 44, write these bytes.”

Three consequences follow directly, and they are the shape of everything in this part:

It is all or nothing. You cannot replicate one database, one schema or one table. A physical standby is a byte-for-byte copy of the entire cluster.

The standby is read-only. It cannot have its own tables, its own indexes, or different data.

Read-only / Safewriting to a standby
$ INSERT INTO t DEFAULT VALUES;
ERROR:  cannot execute INSERT in a read-only transaction

Both sides must be the same major version, architecture and page layout. A byte offset means nothing otherwise. Physical replication cannot be used to upgrade across major versions, which is why Part XVII covers upgrades separately.

In exchange it is cheap, complete and simple. Everything is replicated — DDL, sequences, large objects, extensions, permissions — because everything goes through WAL.

Streaming or archive

A standby has two ways to obtain WAL, and it can use both:

Streaming, over a replication connection, is the low-latency path and the normal one.

Archive, via restore_command, is the same mechanism as recovery in Part XIII. A standby falls back to it when streaming is interrupted, and it is what allows a standby to catch up after being down longer than the primary retained WAL.

Configuring both is the robust arrangement: streaming for latency, the archive as the safety net. Lesson XIV-06 shows what happens when the safety net is a replication slot instead, and the slot is the only thing holding the WAL.

What replication is for, and what it is not for

GoalPhysical replication
Survive a primary host failureYes, with a promotion mechanism (Part XV)
Offload read trafficYes, with caveats (lesson XIV-08)
Reduce read latency in another regionYes
Recover from DROP TABLENo. The drop replicates in milliseconds
Recover from application corruptionNo. Same reason
Cross major-version upgradeNo. Byte-level
Replicate one tableNo. Cluster-wide

The first three are what it does. The rest is what backups are for, and lesson XIII-01 made that argument with the failure that proves it.

What to take from this

  • Replication is crash recovery that never finishes, driven by WAL arriving over a connection.
  • One walsender per standby, one walreceiver per standby, one startup process doing the replay.
  • Physical means byte-level: whole cluster, read-only, same major version and architecture.
  • Streaming for latency, archive as the fallback; configure both.
  • A standby is a complete cluster and fails independently of the primary, silently.
  • Replication is not a backup. A DROP TABLE replicates in milliseconds.

Cross-course references

  • Linux for Production Sysadmins — Part LII (High availability fundamentals) covers where replication sits in an availability argument, and what it does not supply on its own.
  • Observability for Production Sysadmins — Part LIX (Database observability) covers exporting replication state per standby rather than as a single cluster-level number.

Quiz

Knowledge check · 6 questions

  1. Q1. Why can physical streaming replication not be used to replicate a single table to another server?

  2. Q2. A standby's process list shows 'postgres: startup recovering 000000010000000000000005'. What is that process?

  3. Q3. A team relies on a streaming standby as their protection against data loss. Someone runs DROP TABLE orders on the primary. What does the standby provide?

  4. Q4. Which are true of a physical standby? Select all that apply.

  5. Q5. A physical standby can be given an extra index that the primary does not have, since its planner is independent.

  6. Q6. Trace a committed change from the primary to visibility on a standby, and say where the client's COMMIT returns by default.

Passing score: 75%. Answers are checked in this browser.