pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix replay of create database records on standby
Date: Fri, 25 Mar 2022 12:17:12 +0000
Message-ID: <E1nXisR-001Jmp-CM@gemulon.postgresql.org> (raw)

Fix replay of create database records on standby

Crash recovery on standby may encounter missing directories when
replaying create database WAL records.  Prior to this patch, the standby
would fail to recover in such a case.  However, the directories could be
legitimately missing.  Consider a sequence of WAL records as follows:

    CREATE DATABASE
    DROP DATABASE
    DROP TABLESPACE

If, after replaying the last WAL record and removing the tablespace
directory, the standby crashes and has to replay the create database
record again, the crash recovery must be able to move on.

This patch adds a mechanism similar to invalid-page tracking, to keep a
tally of missing directories during crash recovery.  If all the missing
directory references are matched with corresponding drop records at the
end of crash recovery, the standby can safely continue following the
primary.

Backpatch to 13, at least for now.  The bug is older, but fixing it in
older branches requires more careful study of the interactions with
commit e6d8069522c8, which appeared in 13.

A new TAP test file is added to verify the condition.  However, because
it depends on commit d6d317dbf615, it can only be added to branch
master.  I (Álvaro) manually verified that the code behaves as expected
in branch 14.  It's a bit nervous-making to leave the code uncovered by
tests in older branches, but leaving the bug unfixed is even worse.
Also, the main reason this fix took so long is precisely that we
couldn't agree on a good strategy to approach testing for the bug, so
perhaps this is the best we can do.

Diagnosed-by: Paul Guo <paulguo@gmail.com>
Author: Paul Guo <paulguo@gmail.com>
Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Author: Asim R Praveen <apraveen@pivotal.io>
Discussion: https://postgr.es/m/CAEET0ZGx9AvioViLf7nbR_8tH9-=27DN5xWJ2P9-ROH16e4JUA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/49d9cfc68bf4e0d32a948fe72d5a0ef7f464944e

Modified Files
--------------
src/backend/access/transam/xlogrecovery.c   |   6 ++
src/backend/access/transam/xlogutils.c      | 159 +++++++++++++++++++++++++++-
src/backend/commands/dbcommands.c           |  57 ++++++++++
src/backend/commands/tablespace.c           |  17 +++
src/include/access/xlogutils.h              |   4 +
src/test/recovery/t/029_replay_tsp_drops.pl |  67 ++++++++++++
src/tools/pgindent/typedefs.list            |   2 +
7 files changed, 311 insertions(+), 1 deletion(-)



view thread (10+ messages)  latest in thread

Message-ID: <E1nXisR-001Jmp-CM@gemulon.postgresql.org>
Permalink:  ../E1nXisR-001Jmp-CM@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nXisR-001Jmp-CM@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: alvherre@alvh.no-ip.org
  Subject: Re: pgsql: Fix replay of create database records on standby
  In-Reply-To: <E1nXisR-001Jmp-CM@gemulon.postgresql.org>
  References: <E1nXisR-001Jmp-CM@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