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

ValueWhat it waits for before acknowledging the commitWhat can be lost
offNothingRecent commits if the local server stops (up to about 3 times wal_writer_delay)
localLocal WAL fsyncDoes not wait for the replica
remote_writeLocal fsync + the synchronous standby writes the WAL to the operating systemThe standby's copy if the standby's operating system also stops
on (default)Local fsync + the synchronous standby fsyncs the WALNothing
remote_applyThe above, plus the standby applies the WALNothing. The commit is visible even when read from the standby right after
ItemValue
Specifying synchronous standbyssynchronous_standby_names. If empty, local, remote_write, on, and remote_apply all wait only for the local fsync
WAL flush interval when offThe walwriter flushes every wal_writer_delay (default 200ms)
Scope of the settingServer, database, user, session, transaction (SET LOCAL)
Related settingscommit_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

PostgreSQLInnoDBOracleSQL Server
Settingsynchronous_commit = offinnodb_flush_log_at_trx_commit = 0/2COMMIT WRITE NOWAIT / BATCHDelayed Durability
Per-transaction controlYes (SET LOCAL)Server-wideYes (per statement)Yes (COMMIT WITH (DELAYED_DURABILITY = ON))
Scope of lossAbout wal_writer_delay × 3About 1 secondCommits not yet writtenCommits remaining in the log buffer

In the Articles

NOTE The range of time that can be lost may vary with load and version.

Related pages