agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Daniel Gustafsson <dgustafsson@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: pg_rewind: Check the data checksum states of source and target
Date: Mon, 14 Sep 2026 13:34:14 +0000
Message-ID: <E1x66p4-00000000I6L-2R67@gemulon.postgresql.org> (raw)

pg_rewind: Check the data checksum states of source and target

pg_rewind installs the source's control file on the target, but every
block it does not copy keeps the target's content.  With checksums
enabled on the target and disabled on the source, the rewound server
claims enabled checksums while the blocks copied from the source have
none, and fails checksum verification as soon as it reads them; in the
worst case every connection attempt dies on an unverifiable catalog
page.

Comparing the control files is not enough.  Replay on the rewound
server resumes from the last common checkpoint and adopts the data
checksum state recorded there, so an offline disable on the source
after the divergence leaves both control files saying "off" while the
rewound server still resumes with verification enabled.  Check the
state carried by the divergence checkpoint as well, which pg_rewind
already reads.

Refuse both cases, and an interrupted online transition on either
side, same as pg_checksums does.  The opposite mismatch, checksums on
the source only, is allowed with a warning: recovery under the backup
label adopts the divergence state, so the rewound server keeps
checksums disabled (or converges through the replayed WAL if the
source enabled them online), and no page can fail verification.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/anwm6UPxoVS41QA2@bdtpg
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/227f8ea19a6b321af90607fe12d58eb5ce2c2dce

Modified Files
--------------
doc/src/sgml/ref/pg_rewind.sgml                    |  14 ++
src/bin/pg_rewind/parsexlog.c                      |   4 +-
src/bin/pg_rewind/pg_rewind.c                      |  93 ++++++++++++-
src/bin/pg_rewind/pg_rewind.h                      |   1 +
src/test/modules/test_checksums/meson.build        |   2 +
.../modules/test_checksums/t/022_rewind_state.pl   | 145 +++++++++++++++++++
.../test_checksums/t/023_rewind_standby_target.pl  | 153 +++++++++++++++++++++
7 files changed, 410 insertions(+), 2 deletions(-)



Message-ID: <E1x66p4-00000000I6L-2R67@gemulon.postgresql.org>
Permalink:  ../E1x66p4-00000000I6L-2R67@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x66p4-00000000I6L-2R67@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: dgustafsson@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: pg_rewind: Check the data checksum states of source and target
  In-Reply-To: <E1x66p4-00000000I6L-2R67@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox