postgres-impl-streaming-replication
postgres-impl-streaming-replication
Quick Reference :
Streaming (physical) replication ships raw WAL records over TCP from a primary to one or more standbys. The standby is a byte-identical copy of the whole cluster , every database, role, and table , and replays WAL continuously. It is not selective ; for row-level, cross-version replication use logical replication instead.
Setup is three steps : (1) prepare the primary (wal_level = replica, a REPLICATION role, a pg_hba.conf replication line), (2) clone the data directory with pg_basebackup ... -R, (3) start the standby , the standby.signal file puts it in standby mode and it streams from primary_conninfo.
A standby with hot_standby = on (the default) serves read-only queries. A physical replication slot stops the primary from recycling WAL the standby has not consumed yet , but a slot whose consumer is gone grows pg_wal without bound. ALWAYS set max_slot_wal_keep_size (v13+) so a dead slot is invalidated instead of filling the disk.
synchronous_commit trades durability against commit latency. The default on waits for the local WAL flush ; with synchronous_standby_names set it also waits for the standby. NEVER point synchronous_standby_names at a single standby with no quorum , if that standby goes down, every commit on the primary stalls.