Fix replay of create database records on standby
authorAlvaro Herrera <[email protected]>
Thu, 28 Jul 2022 06:40:06 +0000 (08:40 +0200)
committerAlvaro Herrera <[email protected]>
Thu, 28 Jul 2022 06:40:06 +0000 (08:40 +0200)
commit9e4f914b5eba3f49ab99bdecdc4f96fac099571f
tree37d644b03c8d3284e5914cbb3ccbdd6dd664e2f4
parentd396606ebe9722baceabb156551169d83c85b8c8
Fix replay of create database records on standby

Crash recovery on standby may encounter missing directories
when replaying database-creation WAL records.  Prior to this
patch, the standby would fail to recover in such a case;
however, the directories could be legitimately missing.
Consider the following sequence of commands:

    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, crash recovery must be able to continue.

A fix for this problem was already attempted in 49d9cfc68bf4, but it
was reverted because of design issues.  This new version is based
on Robert Haas' proposal: any missing tablespaces are created
during recovery before reaching consistency.  Tablespaces
are created as real directories, and should be deleted
by later replay.  CheckRecoveryConsistency ensures
they have disappeared.

The problems detected by this new code are reported as PANIC,
except when allow_in_place_tablespaces is set to ON, in which
case they are WARNING.  Apart from making tests possible, this
gives users an escape hatch in case things don't go as planned.

Author: Kyotaro Horiguchi <[email protected]>
Author: Asim R Praveen <[email protected]>
Author: Paul Guo <[email protected]>
Reviewed-by: Anastasia Lubennikova <[email protected]> (older versions)
Reviewed-by: Fujii Masao <[email protected]> (older versions)
Reviewed-by: Michaël Paquier <[email protected]>
Diagnosed-by: Paul Guo <[email protected]>
Discussion: https://postgr.es/m/CAEET0ZGx9AvioViLf7nbR_8tH9-=27DN5xWJ2P9-ROH16e4JUA@mail.gmail.com
src/backend/access/transam/xlogrecovery.c
src/backend/commands/dbcommands.c
src/backend/commands/tablespace.c
src/test/recovery/t/033_replay_tsp_drops.pl [new file with mode: 0644]