Don't skip invalid databases when enabling data checksums

When enabling checksums cannot process a database, the launcher uses
DatabaseExists to tell a concurrent drop (benign) from a real failure.
Since 1df361e3d82 that check also treats a present, but-invalid, data-
base as non-existent.  An interrupted DROP DATABASE flush the invalid
marker before the row and files are removed, so a crash or ERROR can
leave an invalid row whose files remain on disk.

Report a database as existing whenever its catalog row is found to
ensure that checksums cannot be enabled if there are invalid databases.
The AccessShareLock in DatabaseExists already waits out an in-flight
drop, so an invalid-but-present row can only be an interrupted drop
leftover whose files still need checksums; enabling then aborts until
it is dropped.

Backpatch to v19 where online checksums were introduced.

Author: Ayush Tiwari <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: 
https://postgr.es/m/CAN4CZFOGdqxtZ5-6gb4apqmvoH=z+tnh8rkj3mvtor1hirk...@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6a6e99f859db1163a3646eaf8e47f865312dfc07

Modified Files
--------------
src/backend/commands/dbcommands.c                  |  2 +
src/backend/postmaster/datachecksum_state.c        | 29 ++++------
src/test/modules/test_checksums/t/005_injection.pl | 63 ++++++++++++++++++++++
3 files changed, 75 insertions(+), 19 deletions(-)

Reply via email to