Synchronous and asynchronous replication
Overview
Asynchronous replication allows commit acknowledgment without waiting for a remote replica. Synchronous replication waits for the configured remote acknowledgment condition, which trades write availability and latency for stronger protection under specified failures. PostgreSQL synchronous_commit=on with synchronous standbys waits for remote flush; remote_write waits for remote OS write; remote_apply waits for replay. Local commit durability is a separate condition. No mode promises survival of all failures.
First example
SELECT node,received>=5,flushed>=5,applied>=5 FROM ra_progress ORDER BY node;Observed SQLite result (rows in JSON):
[ [ "A", 1, 0, 0 ], [ "B", 0, 0, 0 ]]How it works
For event 5, A has received it but only flushed event 4 and applied event 3; B has flushed and applied 4. The first query models remote stages. The second asks whether at least one replica flushed event 4 versus event 5; it is a toy one-ack policy, not PostgreSQL quorum implementation. Read-after-write requires reading the primary or ensuring the selected replica has applied the needed change and using an appropriate fresh snapshot.
Practical example
SELECT MAX(flushed)>=4,MAX(flushed)>=5 FROM ra_progress;Observed SQLite result (rows in JSON):
[ [ 1, 0 ]]Practice and mistakes
Practice: change A applied to 4 in a transaction and compare visibility. Hint 1: received is not applied. Hint 2: check the required stage for each acknowledgment mode. Avoid interpreting an acknowledgment timeout as proof the transaction aborted; reconcile uncertain outcomes using an idempotency key.
PostgreSQL 17 example — NOT RUN
SELECT name,setting FROM pg_settings WHERE name IN ('synchronous_commit','synchronous_standby_names') ORDER BY name;Expected result, not executed: "Inspect configured acknowledgment policy; actual synchronous membership also requires runtime inspection."