Parameter · Write-Ahead Log / Settings
synchronous_commit
Sets the current transaction's synchronization level.
- Default:
on - Type: enum
- Values: local · remote_write · remote_apply · on · off
- Applies: Session (any user)
In plain words
When you COMMIT, PostgreSQL normally waits until the WAL for that transaction is safely on disk before saying "done". synchronous_commit lets you choose how much to wait for. off answers immediately (a crash may lose the last fraction of a second of commits, but never corrupts data). With synchronous standbys configured, on, remote_write and remote_apply also wait for a standby.
It can be set per session or even per transaction, so important writes can wait and unimportant ones do not.
For DBAs and operators
| Value | COMMIT waits until |
|---|---|
off | nothing: WAL is flushed by the WAL writer within about 3 × wal_writer_delay |
local | WAL flushed on the primary |
remote_write | local flush + sync standby(s) wrote it to their OS |
on | local flush + sync standby(s) flushed it to disk |
remote_apply | local flush + sync standby(s) replayed it (visible to queries) |
The remote levels only matter when synchronous_standby_names is non-empty; otherwise on, remote_write and remote_apply behave like local.
off is not like fsync=off
With off the transaction is reported committed before its WAL is durable. A crash can lose those transactions, but the database stays consistent: no corruption, just a short window of lost commits. It's a common, safe trade-off for logging tables or sessions doing many tiny commits: SET LOCAL synchronous_commit = off;.
Waiting for standbys
- Waiting backends show
wait_event = 'SyncRep'inpg_stat_activity. If all sync standbys are gone, commits hang until one returns or the setting changes; the transaction is already locally committed, so canceling the wait gives WARNING: canceling wait for synchronous replication due to user request with "The transaction has already committed locally, but might not have been replicated to the standby." remote_applygives read-your-writes on the standby, but commit latency then includes replay (and anyrecovery_min_apply_delay!).
How to change it
Any user can change it for their session with SET.
See it in context
Synchronous replication Write-ahead log (WAL) WAL writer The big picture Life of a DELETE
Related parameters
synchronous_standby_names wal_writer_delay fsync commit_delay recovery_min_apply_delay