synchronous_commit
synchronous_commit decides what to wait for before reporting that a commit succeeded. The default on waits until the commit's WAL is fsynced to local disk. With off, the server responds before the WAL reaches disk, so commits are faster, but if the server stops abruptly, some recent commits can disappear. WAL order is still preserved, so the database is not corrupted, and a lost transaction is undone entirely as if it never happened.
Key Specifications
| Value | What it waits for before acknowledging the commit | What can be lost |
|---|---|---|
off | Nothing | Recent commits if the local server stops (up to about 3 times wal_writer_delay) |
local | Local WAL fsync | Does not wait for the replica |
remote_write | Local fsync + the synchronous standby writes the WAL to the operating system | The standby's copy if the standby's operating system also stops |
on (default) | Local fsync + the synchronous standby fsyncs the WAL | Nothing |
remote_apply | The above, plus the standby applies the WAL | Nothing. The commit is visible even when read from the standby right after |
| Item | Value |
|---|---|
| Specifying synchronous standbys | synchronous_standby_names. If empty, local, remote_write, on, and remote_apply all wait only for the local fsync |
WAL flush interval when off | The walwriter flushes every wal_writer_delay (default 200ms) |
| Scope of the setting | Server, database, user, session, transaction (SET LOCAL) |
| Related settings | commit_delay, commit_siblings (wait briefly before fsync for group commit) |
How It Works
Choosing per transaction. Instead of setting off for the whole server, only writes that can be lost (logs, session records, statistics) can commit fast with SET LOCAL synchronous_commit = off. Other transactions on the same server keep committing safely with on.
Difference from fsync = off. fsync = off skips the disk confirmation for both WAL and data files, so a crash can corrupt the whole database. synchronous_commit = off only moves the acknowledgment point earlier, so nothing is corrupted. Production systems do not turn fsync off.
Group commit. When many transactions commit at the same time, a single fsync flushes several commits together. With commit_delay (microseconds), if at least commit_siblings transactions are active, the commit waits briefly before fsync to gather more.
Configuration and Inspection
SHOW synchronous_commit;
BEGIN;
SET LOCAL synchronous_commit = off; -- this transaction only
INSERT INTO access_log VALUES (...);
COMMIT;
ALTER ROLE batch_user SET synchronous_commit = off;
-- Synchronous replication status
SELECT application_name, sync_state, write_lag, flush_lag, replay_lag FROM pg_stat_replication;
Comparison with Other DBMSs
| PostgreSQL | InnoDB | Oracle | SQL Server | |
|---|---|---|---|---|
| Setting | synchronous_commit = off | innodb_flush_log_at_trx_commit = 0/2 | COMMIT WRITE NOWAIT / BATCH | Delayed Durability |
| Per-transaction control | Yes (SET LOCAL) | Server-wide | Yes (per statement) | Yes (COMMIT WITH (DELAYED_DURABILITY = ON)) |
| Scope of loss | About wal_writer_delay × 3 | About 1 second | Commits not yet written | Commits remaining in the log buffer |
In the Articles
- 6.2 fsync: Confirming Writes to Durable Media
- 6.3 Group Commit: Many Commits with One fsync
- 6.6 How DBMSs Differ and What You Meet in Practice
NOTE The range of time that can be lost may vary with load and version.