6.6 Differences Between DBMSs and What You Meet in Practice

All four DBMSs do fsync at commit by default, but all of them also have settings that relax this.

DBMSSettingBehavior when relaxed
PostgreSQLsynchronous_commit = offWrites the log to disk asynchronously after the commit response. The most recent few hundred milliseconds of commits may be lost, but the data itself is not corrupted
MySQL (InnoDB)innodb_flush_log_at_trx_commit = 0 or 2fsync once per second. 0 also defers the write to the OS; 2 writes to the OS but defers only fsync
OracleCOMMIT WRITE NOWAIT / BATCHResponds without waiting for the log write to complete
SQL Server / Azure SQLDelayed DurabilityWrites to disk when the log buffer fills or a set time passes

Learn more — synchronous_commit, innodb_flush_log_at_trx_commit, COMMIT WRITE, Delayed Durability

Table 6-1. Settings that relax commit durability, by DBMS

NOTE Setting names, defaults, and allowed values may differ by version. Azure SQL Database is a managed service, so some settings may not be exposed or may behave differently.

These settings all make the same trade-off. They gain throughput by returning the commit response before fsync completes, and in exchange allow "commits whose response was received but that may vanish on failure." The range lost is usually the most recent few hundred milliseconds to about one second. Data pages still follow the first line of the WAL rule, so the database is not corrupted; it is only that the last few transactions become as if they never happened.

There are cases where this trade-off is reasonable. For data that can afford to lose the last second, such as log collection, session records, or regenerable caches, throughput can be increased several times over. Conversely, it cannot be used for data such as payments or transfers, where "having seen the completion response" is itself a legal fact. The important point is that these settings can be changed not only for the whole server but also per session or per transaction. Within one database, a configuration is possible in which transfers wait for fsync and access logs do not.

Another phenomenon frequently met in practice is "commits got slower after moving to a virtual machine or container." The cause is usually that the storage device changed. With network storage or cloud block storage, the round-trip time of one fsync can be longer than on a local SSD, and commit performance depends almost entirely on fsync time. If you meet commit latency that does not improve with more CPU or memory, measure fsync time first.

TIP One-line summary. A "saved" response only means the data arrived in the operating system cache, and the database recognizes a commit only after confirming with fsync that it reached disk. The cost of fsync is shared out by group commit, and dirty pages are cleaned up periodically by checkpoints to narrow the recovery range. With this, the problem of atomicity and durability, that is, "even if the server goes down," is settled. The next chapter turns to the problem of "many people at once": isolation.