Parameter · Replication / Primary Server
synchronous_standby_names
Number of synchronous standbys and list of names of potential synchronous ones.
- Default:
'' (empty) - Type: string
- Applies: Reload
In plain words
Normally COMMIT returns as soon as the primary has saved the change to its own WAL; standbys get it a moment later (asynchronous). Listing standbys here makes replication synchronous: COMMIT waits until enough of them confirm they have the change too, so a primary failure loses no committed data.
FIRST 1 (s1, s2) waits for the highest-priority connected standby; ANY 2 (s1, s2, s3) waits for any two. If no listed standby is available, commits wait forever.
For DBAs and operators
Names match a standby's application_name (set in its primary_conninfo; default is cluster_name or walreceiver). * matches anything. Syntax:
FIRST n (a, b, c): priority. The first n connected names in list order are sync; others are potential and take over when one disappears.ANY n (a, b, c): quorum. Any n confirmations suffice; all listed are quorum.a, b(no keyword): legacy form, same asFIRST 1 (a, b).
What "confirm" means is set by synchronous_commit (remote_write, on = flushed, remote_apply). It can be turned off per transaction for unimportant writes.
LOG: standby "s1" is now a synchronous standby with priority 1
LOG: standby "s2" is now a candidate for quorum synchronous standby
SELECT application_name, state, sync_priority, sync_state, replay_lag
FROM pg_stat_replication;Support notes
- Hanging commits with
wait_event = 'SyncRep'inpg_stat_activity: not enough sync standbys connected. Fix the standby, or reduce the list and reload. - Cancelling a waiting commit gives WARNING: canceling wait for synchronous replication due to user request DETAIL: The transaction has already committed locally, but might not have been replicated to the standby.
- Use at least one more candidate than n, otherwise one standby outage stops all writes.
How to change it
Change in postgresql.conf or ALTER SYSTEM, then run SELECT pg_reload_conf().
See it in context
Related parameters
synchronous_commit primary_conninfo wal_sender_timeout max_wal_senders