pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix partial two-phase files left by crash during checkpoint
Date: Mon, 26 Oct 2026 08:17:27 +0000
Message-ID: <E1xLFtX-00000000oGD-2lF8@gemulon.postgresql.org> (raw)

Fix partial two-phase files left by crash during checkpoint

CheckPointTwoPhase() wrote each 2PC file in place, with O_TRUNC.  A
crash mid-write, or a base backup copying the file at that point left an
empty or partial file that would make startup fail, most likely on an
"incorrect size of file" ERROR.

The 2PC files are now written through a temporary file that gets renamed
at the end, relying on the atomicity of the rename to make startup safe,
be it after a crash or a base backup.

Author: Shihao Zhong <zhong950419@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: David Steele <david@pgbackrest.org>
Discussion: https://postgr.es/m/CAGRkXqS_On-pLgcv6xjH8mvGhdcPmfWtythW3r8pYKUG+hsiuQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4b9009105b7a037b9025a4bc7f3c65445dcaaca8

Modified Files
--------------
src/backend/access/transam/twophase.c | 40 +++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xLFtX-00000000oGD-2lF8@gemulon.postgresql.org>
Permalink:  ../E1xLFtX-00000000oGD-2lF8@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xLFtX-00000000oGD-2lF8@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: michael@paquier.xyz
  Subject: Re: pgsql: Fix partial two-phase files left by crash during checkpoint
  In-Reply-To: <E1xLFtX-00000000oGD-2lF8@gemulon.postgresql.org>
  References: <E1xLFtX-00000000oGD-2lF8@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