Pcornel
Databases · Replication & High Availability

PostgreSQL Streaming Replication

Cheat sheet · https://pcornel.dk/topic.php?topic=6187

Back to the Topic

Answer

PostgreSQL streaming replication sends WAL from the primary to standbys over a replication connection; standbys replay it and can serve read-only queries.

Remember

Use replication slots carefully (they retain WAL). Monitor lag in bytes and time. Synchronous standbys block commits if they are down.

First checks

  • SELECT client_addr,state,sent_lsn,replay_lsn FROM pg_stat_replication; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

primary WAL → walsender → walreceiver → replay on standby

Where it usually breaks

Without a slot or enough wal_keep_size, a lagging standby can fall behind permanently.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6187

Confirmation

Confirm action

Continue?