pgsql: PANIC on fsync() failure.

From: Thomas Munro <tmunro(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: PANIC on fsync() failure.
Date: 2018-11-19 04:45:24
Message-ID: E1gObR6-00023g-5u@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

PANIC on fsync() failure.

On some operating systems, it doesn't make sense to retry fsync(),
because dirty data cached by the kernel may have been dropped on
write-back failure. In that case the only remaining copy of the
data is in the WAL. A subsequent fsync() could appear to succeed,
but not have flushed the data. That means that a future checkpoint
could apparently complete successfully but have lost data.

Therefore, violently prevent any future checkpoint attempts by
panicking on the first fsync() failure. Note that we already
did the same for WAL data; this change extends that behavior to
non-temporary data files.

Provide a GUC data_sync_retry to control this new behavior, for
users of operating systems that don't eject dirty data, and possibly
forensic/testing uses. If it is set to on and the write-back error
was transient, a later checkpoint might genuinely succeed (on a
system that does not throw away buffers on failure); if the error is
permanent, later checkpoints will continue to fail. The GUC defaults
to off, meaning that we panic.

Back-patch to all supported releases.

There is still a narrow window for error-loss on some operating
systems: if the file is closed and later reopened and a write-back
error occurs in the intervening time, but the inode has the bad
luck to be evicted due to memory pressure before we reopen, we could
miss the error. A later patch will address that with a scheme
for keeping files with dirty data open at all times, but we judge
that to be too complicated to back-patch.

Author: Craig Ringer, with some adjustments by Thomas Munro
Reported-by: Craig Ringer
Reviewed-by: Robert Haas, Thomas Munro, Andres Freund
Discussion: https://postgr.es/m/20180427222842.in2e4mibx45zdth5%40alap3.anarazel.de

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/afbe03f6547015790d13d21d5eb5083cc604eeec

Modified Files
--------------
doc/src/sgml/config.sgml | 32 ++++++++++++++++++
src/backend/access/heap/rewriteheap.c | 6 ++--
src/backend/access/transam/slru.c | 2 +-
src/backend/access/transam/timeline.c | 4 +--
src/backend/access/transam/xlog.c | 2 +-
src/backend/replication/logical/snapbuild.c | 3 ++
src/backend/storage/file/fd.c | 48 +++++++++++++++++++++++----
src/backend/storage/smgr/md.c | 6 ++--
src/backend/utils/cache/relmapper.c | 2 +-
src/backend/utils/misc/guc.c | 9 +++++
src/backend/utils/misc/postgresql.conf.sample | 1 +
src/include/storage/fd.h | 2 ++
12 files changed, 99 insertions(+), 18 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2018-11-19 04:45:39 pgsql: PANIC on fsync() failure.
Previous Message Thomas Munro 2018-11-19 04:45:10 pgsql: Don't forget about failed fsync() requests.