pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@postgresql.org
Subject: pgsql: Avoid unlikely data-loss scenarios due to rename() without fsync
Date: Thu, 10 Mar 2016 03:25:21 +0000
Message-ID: <E1adrE1-0001PP-Vx@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Avoid unlikely data-loss scenarios due to rename() without fsync.

Renaming a file using rename(2) is not guaranteed to be durable in face
of crashes. Use the previously added durable_rename()/durable_link_or_rename()
in various places where we previously just renamed files.

Most of the changed call sites are arguably not critical, but it seems
better to err on the side of too much durability.  The most prominent
known case where the previously missing fsyncs could cause data loss is
crashes at the end of a checkpoint. After the actual checkpoint has been
performed, old WAL files are recycled. When they're filled, their
contents are fdatasynced, but we did not fsync the containing
directory. An OS/hardware crash in an unfortunate moment could then end
up leaving that file with its old name, but new content; WAL replay
would thus not replay it.

Reported-By: Tomas Vondra
Author: Michael Paquier, Tomas Vondra, Andres Freund
Discussion: 56583BDD.9060302@2ndquadrant.com
Backpatch: All supported branches

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/a62714fae23d2056242bb2ac872111cab8f9fbd1

Modified Files
--------------
contrib/pg_stat_statements/pg_stat_statements.c |  6 +--
src/backend/access/transam/xlog.c               | 66 +++++--------------------
src/backend/postmaster/pgarch.c                 |  6 +--
3 files changed, 13 insertions(+), 65 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


view thread (6+ messages)

Message-ID: <E1adrE1-0001PP-Vx@gemulon.postgresql.org>
Permalink:  ../E1adrE1-0001PP-Vx@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1adrE1-0001PP-Vx@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Avoid unlikely data-loss scenarios due to rename() without fsync
  In-Reply-To: <E1adrE1-0001PP-Vx@gemulon.postgresql.org>
  References: <E1adrE1-0001PP-Vx@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox