Scrivio Interview library
InternalsIntermediate7 min read · updated 12 November 2026

In 2018 PostgreSQL developers found that on Linux a failed fsync could be reported once and then the dirty pages dropped, so a later fsync succeeded although data was lost. Explain the problem, what PostgreSQL changed, and what else can break the durability promise between the database and the disk.

When writing dirty pages back failed, Linux could report the error to one fsync call, then mark the pages clean and forget the error, so the next fsync succeeded even though the data never reached the disk; PostgreSQL assumed it could simply retry and would then consider a checkpoint complete. PostgreSQL now treats any fsync failure on data files as fatal, PANICs and recovers from the WAL on restart (data_sync_retry defaults to off). Other things can still break durability: torn pages, which full_page_writes and InnoDB's doublewrite buffer guard against, and storage or virtualization layers that acknowledge flushes they have not made durable, so we test with pg_test_fsync, choose storage with honest flush semantics and enable data checksums.

Why this question is asked

The 2018 discovery, often called fsyncgate, showed that a database can do everything right by its own understanding and still lose committed data because of an assumption about the layer below. It changed PostgreSQL's error handling, influenced Linux error reporting, and is a good lesson in how durability is a chain of promises. Interviewers ask about it to see whether we understand what fsync really guarantees and what else sits between COMMIT and the platter. In this answer, we will recap how PostgreSQL uses fsync, explain the failure, see what PostgreSQL changed and why, and then cover the other ways the promise can break and how to guard against them.

1A Quick Recap: How PostgreSQL Uses fsync

PostgreSQL writes data pages through the operating system. When it writes a dirty page, the kernel copies it into the page cache and returns; the kernel writes it to the device later, in writeback. To be sure the pages are on disk, PostgreSQL calls fsync on the data files, in particular at the end of each checkpoint. Only when those fsync calls succeed does it record the checkpoint and allow the WAL before it to be removed.

That last step is where the trust lies. Once the checkpoint is recorded, the WAL that could rebuild those pages is gone, so the data files are the only copy. If an fsync reported success for data that was not actually written, nothing can recover it.

2What Went Wrong

Suppose the storage fails a write during writeback, for example a transient error on a SAN path or a thin-provisioned volume running out of space. The kernel tries to write a dirty page and gets an I/O error. In the behaviour PostgreSQL developers found, Linux then marked the page clean, so it would not keep retrying a write that might never succeed, and recorded an error that it reported to the next fsync on the file. Depending on the kernel version, that report could even go to a different process or be lost if the file had been closed in between, which PostgreSQL does routinely.

PostgreSQL's checkpointer saw the fsync fail, logged an error and, following the long-held assumption that a failed fsync could be retried, tried again at the next checkpoint. The second fsync succeeded, because there were no dirty pages left and no error recorded. PostgreSQL concluded the data was safe, completed the checkpoint and discarded the WAL. The page on disk was the old version, and the change was silently lost.

Step throughA failed write that the retry hides
CheckpointerLinux kernelStorage
write(page 7), returns at once
writeback page 7
I/O error
mark page 7 clean, remember error
fsync(file)
EIO, error now cleared
next checkpoint: fsync(file) again
success, nothing dirty
checkpoint done, old WAL removed

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

Page 7's change exists nowhere: not on disk, not in the page cache and no longer in the WAL.

3What PostgreSQL Changed

The fix was to stop trusting a retry. Since the minor releases published in early 2019, PostgreSQL treats a failed fsync of a data file as unrecoverable for the running server: it raises a PANIC, which stops the server, and on restart performs normal crash recovery. Recovery starts from the last checkpoint that really completed, and the WAL from that point is still present because the failed checkpoint never finished, so the lost writes are replayed from the WAL. The parameter data_sync_retry, which defaults to off, controls this; turning it on restores the old retry behaviour and is only safe on systems known to keep dirty data after a failed flush.

Linux also improved: since kernel 4.13, writeback errors are tracked per file so that every file descriptor open at the time sees the error at its next fsync. That makes errors harder to lose, but it still does not make a retry rewrite the data, so PostgreSQL keeps its PANIC policy. Other databases revisited similar assumptions after the discussion.

SQL
-- PostgreSQL log after the fix (wording varies by version)
PANIC: could not fsync file "base/16384/24576": Input/output error
LOG: database system was interrupted; last known up at ...
LOG: redo starts at 4A/12000028 -- replays from the last completed checkpoint
SHOW data_sync_retry; -- off

4Torn Pages

Durability can also break inside a single page. A PostgreSQL page is 8 KB, but storage may only guarantee atomic writes of 512 bytes or 4 KB. If the power fails in the middle of writing a page, the page on disk can be part new and part old, a torn page, and WAL replay cannot fix it, because a WAL record describes a change to a valid page, not a whole page.

PostgreSQL's answer is full_page_writes: the first time a page changes after a checkpoint, the WAL contains a full image of it, so recovery can restore the whole page and then apply later changes. InnoDB solves the same problem with the doublewrite buffer: before writing a page to its real location, it writes it to a separate doublewrite area and flushes that; after a crash, a torn page is repaired from its intact copy.

5Storage That Does Not Keep Its Promise

Everything above assumes that when the device says a flush is complete, the data is on persistent media. That is not always true. Consumer disks and some controllers acknowledge writes once they are in a volatile cache, without a battery or capacitors to protect it against power loss. Some virtualization layers, network block devices or misconfigured file systems ignore or delay flush requests for speed. Such systems are fast and lose committed data when the power fails, however carefully the database behaves.

So the storage layer is part of the durability design. We choose disks and cloud volumes whose flush semantics are documented, check that write caches are protected, and measure. pg_test_fsync shows how many flushes per second a volume really does; a laptop SSD claiming a hundred thousand durable flushes per second is almost certainly not flushing.

Step throughThe chain behind a durable commit
  1. PostgreSQLWAL flush at commit, PANIC on fsync failure
  2. Operating systempage cache, writeback, error reporting
  3. File systemhonours flush and barrier requests
  4. Virtualization or network storagemust pass flushes through
  5. Devicecache with power-loss protection or no volatile cache

5 layers, from the top down. Step through them one at a time.

Durability holds only if every layer keeps its promise.

6Testing and Detecting

We test with pg_test_fsync before trusting a new platform, and include pulling the power or killing the virtual machine under load in acceptance tests for critical databases, then verifying that every acknowledged transaction is present. We enable data checksums, set at initdb time or later with pg_checksums on a stopped cluster (PostgreSQL 18 enables them by default for new clusters, check your version), so corrupted pages are detected when read instead of silently returning wrong data. And we monitor the logs for I/O errors and PANICs, which now mean the database is protecting us rather than failing randomly.

7Follow-up questions

What do PostgreSQL data checksums detect and not detect?

Each data page stores a checksum calculated when it is written, and PostgreSQL verifies it when the page is read from disk, so checksums detect pages altered by storage errors, bit flips or partial writes and stop us from reading them as valid data. They do not detect a lost write, where the device returns an older but internally valid version of the page, because that old page has a correct checksum. They also do not cover corruption in memory before the checksum is computed, logical errors written by the application, or the WAL and other files, which have their own checks.

Why not just retry the fsync until it succeeds?

Because after a failed writeback the kernel may have dropped or marked clean the pages that failed, so a later successful fsync says nothing about them. The only copy of the change that is certainly intact is in the WAL, which is why crashing and replaying it is the safe response.

Does this affect databases that use direct I/O?

Less, because with direct I/O the database writes straight to the device and sees errors on the write itself, without relying on the page cache. That is one reason engines such as InnoDB, which commonly use O_DIRECT for data files, were less exposed, though their log files and file system metadata still depend on correct flush semantics.

8Conclusion

In this answer, we saw that Linux could report a failed writeback once, mark the pages clean and clear the error, so PostgreSQL's retried fsync succeeded and a checkpoint discarded WAL for data that was never written. PostgreSQL now PANICs on fsync failure and recovers from the WAL, with data_sync_retry off by default. Torn pages are handled by full_page_writes and InnoDB's doublewrite buffer, while storage that acknowledges flushes from volatile caches can still lose committed data, so we test with pg_test_fsync, choose honest storage, run power-loss tests and enable data checksums.

What to say in the interviewAbout 100 seconds aloud

Open with

PostgreSQL writes data pages into the OS page cache and calls fsync at the end of each checkpoint; once fsync succeeds it records the checkpoint and recycles the older WAL, so the data files become the only copy.

Then, if they want more

In 2018 developers found that when writeback to the device failed, Linux could report the error to one fsync, mark the dirty pages clean and clear the error, and on some kernels the error could even go to another file descriptor or be lost.

PostgreSQL assumed a failed fsync could be retried, so the next checkpoint's fsync succeeded, the checkpoint completed, the WAL was removed, and the change was gone for good.

The fix was to stop retrying: since early 2019 minor releases, an fsync failure on a data file causes a PANIC, the server restarts and replays the WAL from the last real checkpoint, which is still there. data_sync_retry controls it and defaults to off. Linux 4.13 also improved error reporting per file.

Beyond that, durability can break with torn pages, an 8 KB page half written during power loss, which full_page_writes in PostgreSQL and the doublewrite buffer in InnoDB repair. And it can break below the database: disks with volatile write caches and no power-loss protection, or virtualization and network storage that ignore flushes, acknowledge data that is not durable.

So I would test volumes with pg_test_fsync and power-loss tests, choose storage with documented flush semantics, enable data checksums to detect corruption, and alert on I/O errors.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 18
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 "In 2018 PostgreSQL developers found that on Linux a failed fsync could be reported once...": https://scrivio-interview-library.netlify.app/databases/storage-internals/4643bf8e1b/