liveBook · Manning

Synchronous replication

As explained in PostgreSQL Mistakes and How to Avoid Them

Synchronous replication requires configured replication standbys to confirm replicated changes before the committing transaction completes.

Synchronous replication makes configured standbys confirm replicated changes before the committing transaction completes. It can reduce stale-read risk and help prevent distributed serialization anomalies, but every commit pays the network round-trip cost. section 5.6

The correctness–latency tradeoff

A report running on standby beta reads rows while users modify and vacuum them on primary alpha. The report can fail with “canceling statement due to conflict with recovery” when recovery removes row versions it still needs. Synchronous replication may prevent this class of stale-read or read-write conflict, but the resulting latency can bottleneck database performance. Read replicas remain useful for workload offloading, but not inside an application atomic operation spread across nodes. section 5.6

SELECT sum(balance) FROM test.accounts
UNION SELECT avg(balance)
FROM test.accounts;
ERROR:  canceling statement due to conflict with recovery
DETAIL:  User query might have needed to see row versions that must be removed.

Inspect the concrete recovery-conflict error produced when a long-running standby query needs row versions removed by primary-side cleanup. section 5.6

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains commit confirmation, conflict prevention, network latency, and distributed-transaction limits without configuration details.
Examples
Demonstrates a long-running standby report conflicting with primary updates and VACUUM cleanup.
What you can do after
Evaluate whether synchronous confirmation justifies its latency when choosing consistency guarantees for replicated workloads.
How it connects
Connects synchronous replication with read replicas, ACID isolation, distributed transactions, multi-master systems, and PACELC.

Also explained in

Compare how 2 books explain synchronous replication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.