What is the difference between fsync
and synchronous_commit
? I read the documentation, the only thing I understood is both of them are trying to make updates physically written to disk.
Postgresql – Difference between fsync and synchronous_commit – postgresql
postgresql
Related Question
- PostgreSQL 9.6 Beta1 – New Setting ‘remote_apply’ for Configuration Parameter ‘synchronous_commit’
- Postgresql – the difference in performance between a two single-field indexes and one compound index
- PostgreSQL – Difference Between VACUUM and VACUUM ANALYZE
- PostgreSQL – Difference Between Tuples Inserted and Live Tuples
- PostgreSQL Tuples – Difference Between Fetched and Returned Tuples
- PostgreSQL – Difference Between Collations ‘C’ and ‘C.UTF-8’
- Postgresql – For some reason synchronous replication does not work (everything works asynchronously)
Best Answer
When
fsync
is OFF, the PostgreSQL server will never issue anyfsync
system call, leaving entirely to the operating system the decision as to which blocks to transfer from write cache to disk, and when. The database engine never knows what has been sync'ed or not. In case of a server crash, it has to be assumed that the database is in an inconsistent state.When
synchronous_commit
is OFF, the server issuesfsync
call, but not necessarily immediately at commit time for each transaction. It may delay them after the commit, for a maximum ofwal_writer_delay
multiplied by 3. With a default configuration that would be 600ms. This allows to reduce the number of fsync calls, especially for workloads with lots of small transactions. In case of a server crash, the transactions not yet sync'ed in the last 600ms before the crash may be rolled back, but the state of the database is always consistent.