Fix data loss in wal_level=minimal crash recovery of CREATE TABLESPACE.
authorNoah Misch <[email protected]>
Sat, 28 Aug 2021 06:33:23 +0000 (23:33 -0700)
committerNoah Misch <[email protected]>
Sat, 28 Aug 2021 06:42:53 +0000 (23:42 -0700)
commitf11c1bb17099834a3640a750b263e08f5e6f8135
tree408d144845d03957d3b43fb0384990a56e18f1b0
parent6a787c83c48a4d87d5aaa57776015ab77934d0ce
Fix data loss in wal_level=minimal crash recovery of CREATE TABLESPACE.

If the system crashed between CREATE TABLESPACE and the next checkpoint,
the result could be some files in the tablespace unexpectedly containing
no rows.  Affected files would be those for which the system did not
write WAL; see the wal_skip_threshold documentation.  Before v13, a
different set of conditions governed the writing of WAL; see v12's
<sect2 id="populate-pitr">.  (The v12 conditions were broader in some
ways and narrower in others.)  Users may want to audit non-default
tablespaces for unexpected short files.  The bug could have truncated an
index without affecting the associated table, and reindexing the index
would fix that particular problem.

This fixes the bug by making create_tablespace_directories() more like
TablespaceCreateDbspace().  create_tablespace_directories() was
recursively removing tablespace contents, reasoning that WAL redo would
recreate everything removed that way.  That assumption holds for other
wal_level values.  Under wal_level=minimal, the old approach could
delete files for which no other copy existed.  Back-patch to 9.6 (all
supported versions).

Reviewed by Robert Haas and Prabhat Sahu.  Reported by Robert Haas.

Discussion: https://postgr.es/m/CA+TgmoaLO9ncuwvr2nN-J4VEP5XyAcy=zKiHxQzBbFRxxGxm0w@mail.gmail.com
src/backend/commands/tablespace.c