pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Álvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid deleting critical WAL segments during pg_rewind
Date: Fri, 15 Nov 2024 12:10:13 +0000
Message-ID: <E1tBv9R-001vjf-Dl@gemulon.postgresql.org> (raw)

Avoid deleting critical WAL segments during pg_rewind

Previously, in unlucky cases, it was possible for pg_rewind to remove
certain WAL segments from the rewound demoted primary.  In particular
this happens if those files have been marked for archival (i.e., their
.ready files were created) but not yet archived; the newly promoted node
no longer has such files because of them having been recycled, but they
are likely critical for recovery in the demoted node.  If pg_rewind
removes them, recovery is not possible anymore.

Fix this by maintaining a hash table of files in this situation in the
scan that looks for a checkpoint, which the decide_file_actions phase
can consult so that it knows to preserve them.

Backpatch to 14.  The problem also exists in 13, but that branch was not
blessed with commit eb00f1d4bf96, so this patch is difficult to apply
there.  Users of older releases will just have to continue to be extra
careful when rewinding.

Co-authored-by: Полина Бунгина (Polina Bungina) <bungina@gmail.com>
Co-authored-by: Alexander Kukushkin <cyberdemn@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Discussion: https://postgr.es/m/CAAtGL4AhzmBRsEsaDdz7065T+k+BscNadfTqP1NcPmsqwA5HBw@mail.gmail.com

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/bin/pg_rewind/filemap.c                   | 84 ++++++++++++++++++++++++---
src/bin/pg_rewind/filemap.h                   |  3 +
src/bin/pg_rewind/parsexlog.c                 | 21 +++++++
src/bin/pg_rewind/pg_rewind.c                 |  3 +
src/bin/pg_rewind/t/010_keep_recycled_wals.pl | 62 ++++++++++++++++++++
src/tools/pgindent/typedefs.list              |  2 +
6 files changed, 168 insertions(+), 7 deletions(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1tBv9R-001vjf-Dl@gemulon.postgresql.org>
Permalink:  ../E1tBv9R-001vjf-Dl@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tBv9R-001vjf-Dl@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: alvherre@alvh.no-ip.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid deleting critical WAL segments during pg_rewind
  In-Reply-To: <E1tBv9R-001vjf-Dl@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