Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What does it mean that a committed transaction is durable? Explain what the database must do before it reports COMMIT success, and what synchronous_commit = off in PostgreSQL and innodb_flush_log_at_trx_commit = 2 in MySQL change.

A committed transaction is durable when its changes survive a crash once COMMIT has returned. To promise that, the database must write the transaction's WAL or redo records and flush them to stable storage with fsync or an equivalent before reporting success; the data pages can be written later because the log can replay them. synchronous_commit = off in PostgreSQL returns before that flush, so a crash can lose the last fraction of a second of commits without corrupting anything; innodb_flush_log_at_trx_commit = 2 writes the log at commit but flushes about once a second, so an OS crash or power loss can lose up to a second, and 0 can lose up to a second even when only MySQL crashes.

Why this question is asked

Durability is the D in ACID, and it is the promise our payment code relies on when it tells a customer that the money was received. It is also the property teams are most tempted to weaken for speed, because flushing to disk is the slowest part of a commit. Interviewers ask this to see whether we know exactly what is being traded when those settings change. In this answer, we will see what the database does before COMMIT returns, why data pages can wait, what the PostgreSQL and MySQL settings change and how much can be lost, and how group commit makes durability cheaper.

1What Durable Means

Durable means that once the database has told us COMMIT succeeded, the change will still be there after any crash: the database process dying, the operating system panicking or the power going out. It does not cover the disk itself being destroyed; that is what replication and backups are for.

The difficulty is that writes normally do not go straight to the disk. When a program writes to a file, the operating system copies the data into its page cache in memory and returns at once; it writes to the device later. If the power fails in between, that data is gone. So a database cannot simply write; it must force the data down to stable storage, and on Linux that is what fsync and fdatasync do: they return only when the device reports the data as stored.

2What Happens Before COMMIT Returns

During the transaction, every change is applied to pages in memory and described in log records. At COMMIT, the database writes a commit record to the log and flushes the log up to and including that record. Only when the flush completes does it report success to the client. The changed data pages are not flushed; they stay dirty in memory and are written later by background writers and checkpoints.

This is safe because the log is enough to rebuild them. If the server crashes before the pages are written, recovery reads the log from the last checkpoint and replays every committed change onto the old pages. And the log flush is relatively cheap: it is a sequential write of a few kilobytes, rather than random writes of many 8 or 16 KB pages.

Step throughA durable commit
ApplicationDatabaseLog on diskData files
UPDATE account ...
change page in memory, write log record
COMMIT
write commit record and fsync
flushed
COMMIT OK
later: checkpoint writes the page

7 messages in order. Play them, or step through them one at a time.

Success is reported only after the log flush; the page itself is written much later.

3Synchronous_commit = off in PostgreSQL

With synchronous_commit = off, PostgreSQL writes the commit record into the WAL buffers and returns success immediately, without waiting for the flush. The WAL writer process flushes the WAL in the background every wal_writer_delay, 200 milliseconds by default, so the window of risk is short: the documentation puts the worst case at three times wal_writer_delay, about 600 milliseconds of transactions.

The important point is what is lost and what is not. If the server crashes, transactions that reported success in that window may disappear, as if they had never committed. But the database stays consistent: no half-applied transactions and no corruption, because WAL is still written in order and recovery replays everything up to the last flushed record. That makes it suitable for data we can afford to lose, such as activity logs or session refreshes, and wrong for payments.

SQL
-- for one transaction only, the rest of the system stays fully durable
BEGIN;
SET LOCAL synchronous_commit = off;
INSERT INTO page_view (user_id, url) VALUES (42, '/home');
COMMIT; -- returns before the WAL flush; may be lost in a crash within about 600 ms

4Innodb_flush_log_at_trx_commit in MySQL

InnoDB has three settings. With 1, the default, each commit writes the redo log to the operating system and flushes it, fully durable. With 2, each commit writes the redo log to the operating system but flushes only about once per second. A crash of MySQL alone loses nothing, because the data is already in the OS page cache and the OS will write it, but an OS crash or power loss can lose up to about a second of commits. With 0, the redo log is written and flushed only about once per second, so even a MySQL crash can lose up to a second of transactions.

On a replicated MySQL setup, the binary log has its own setting, sync_binlog, and full durability needs sync_binlog = 1 as well, so the binary log and the redo log agree after a crash.

Commit settings and what a crash can lose
SettingFlush at commitMySQL or DB crashOS crash or power loss
PostgreSQL synchronous_commit = onyesnothingnothing
PostgreSQL synchronous_commit = offno, WAL writer ~200 msup to ~600 msup to ~600 ms
InnoDB flush_log_at_trx_commit = 1yesnothingnothing
InnoDB flush_log_at_trx_commit = 2write to OS onlynothingup to ~1 s
InnoDB flush_log_at_trx_commit = 0noup to ~1 sup to ~1 s
None of these settings corrupts data; they only allow the most recent commits to be lost.

5Why Group Commit Makes Durability Cheaper

A flush to an SSD might take a few hundred microseconds, and on network storage a millisecond or more. If each commit needed its own flush, a single connection could commit only about a thousand times per second. Group commit removes most of that limit under concurrency. While one flush is in progress, other transactions that reach COMMIT add their records to the log buffer, and the next flush covers all of them at once. With 50 sessions committing at the same time, one fsync can make 50 transactions durable.

That is why durable commits cost much more for a single-threaded loop of tiny transactions than for a busy multi-user application, and why batching many rows into one transaction is often a better optimisation than turning off synchronous commit.

6Follow-up questions

Can synchronous_commit be changed per transaction?

Yes, and that is its best use. SET LOCAL synchronous_commit = off inside a transaction affects only that transaction, and the setting can also be set per session, per role or per database. So a service can keep payments fully durable and write low-value events with asynchronous commit in the same database. InnoDB's innodb_flush_log_at_trx_commit, by contrast, is a global setting.

Does synchronous_commit = off risk inconsistency between tables?

No. Transactions are still atomic and WAL is replayed in order, so after a crash we see the database as of some earlier moment, with every transaction either fully present or fully absent. What we lose is the guarantee that a transaction reported as committed is among those present.

Is the flush itself always trustworthy?

Only if the storage honours it. Disks or virtual volumes that acknowledge writes from a volatile cache without power-loss protection can lose committed data even with every setting at its safest, so the storage layer must be part of the durability decision.

7Conclusion

In this answer, we saw that a durable commit survives any crash once COMMIT returns, which requires flushing the WAL or redo log to stable storage before reporting success, while data pages are written later and rebuilt from the log if needed. synchronous_commit = off returns before the flush and can lose about the last 600 milliseconds of commits without corrupting data. innodb_flush_log_at_trx_commit = 2 can lose about a second on an OS crash or power loss, and 0 even on a MySQL crash. Group commit lets many transactions share one flush, which keeps durability affordable under concurrency.

What to say in the interviewAbout 100 seconds aloud

Open with

Durable means that once COMMIT has returned, the change survives a crash of the database, the operating system or the power. Because writes normally land in the OS page cache first, the database has to force its log to stable storage before it can say yes.

Then, if they want more

So at commit it writes the commit record to the WAL or redo log and calls fsync or an equivalent, and only after that returns does the client get success.

The data pages stay dirty in memory and are written later by checkpoints, which is safe because recovery can replay the log onto the old pages. synchronous_commit off in PostgreSQL skips waiting for that flush: COMMIT returns immediately and the WAL writer flushes every 200 milliseconds, so a crash can lose up to about three times that, roughly 600 milliseconds of commits.

Nothing is corrupted; we just lose the newest transactions, so it suits activity logs, not payments, and it can be set per transaction with SET LOCAL. In MySQL, innodb_flush_log_at_trx_commit 1 flushes at every commit.

With 2, commit writes the redo log to the OS but flushes about once a second, so a MySQL crash loses nothing but an OS crash or power loss can lose about a second. With 0 even a MySQL crash can lose a second. And for replication sync_binlog matters too.

Finally, group commit lets many concurrent transactions share one fsync, so durability is cheap under load and expensive mainly for tiny single-threaded transactions.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does it mean that a committed transaction is durable? Explain what the database...": https://scrivio-interview-library.netlify.app/databases/storage-internals/99b2fa1f70/