pgsql: Don't skip invalid databases when enabling data checksums

From: Daniel Gustafsson <dgustafsson(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Don't skip invalid databases when enabling data checksums
Date: 2026-08-03 18:52:44
Message-ID: E1wqxmG-000000002z2-1GhB@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <ayushtiwari(dot)slg01(at)gmail(dot)com>
Reviewed-by: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Reviewed-by: Daniel Gustafsson <daniel(at)yesql(dot)se>
Discussion: https://postgr.es/m/CAN4CZFOGdqxtZ5-6gb4apqmvoH=Z+TNH8RKJ3mVtoR1HirKQWg@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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-08-03 18:53:29 pgsql: Don't skip invalid databases when enabling data checksums
Previous Message Jeff Davis 2026-08-03 18:39:24 pgsql: Do not log subscription conninfo.