pgsql: Recheck checksum state before file_copy during CREATE DATABASE

From: Daniel Gustafsson <dgustafsson(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Recheck checksum state before file_copy during CREATE DATABASE
Date: 2026-07-28 19:59:30
Message-ID: E1wonxa-00000000hhE-3L4k@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Recheck checksum state before file_copy during CREATE DATABASE

The file_copy strategy check in createdb() runs during option
validation, before the transaction has an XID and before the
pg_database row exists, so the datachecksumsworker launcher
can start in that window and see neither the new database nor
the transaction creating it. It then raw-copies a template
that was not processed yet, and those files stay unchecksummed,
failing verification from then on.

Recheck the state in CreateDatabaseUsingFileCopy(): the XID is
assigned by then, so a launcher starting after this point waits
for the transaction and finds the new database, and the copy
errors out instead. Add an injection point before the catalog
insert to test the window.

Backpatch to v19 where online checksums were introduced.

Author: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Reviewed-by: Daniel Gustafsson <daniel(at)yesql(dot)se>
Discussion: https://postgr.es/m/CAN4CZFPEBsz8JeY4ixQ1V4ZL_xOY6pJaZS8ZLGH7R+wF--pEtg@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9eb77f9fc80db071b434aea58681ed2adb9038d3

Modified Files
--------------
src/backend/commands/dbcommands.c | 28 +++++++++
src/test/modules/test_checksums/t/005_injection.pl | 68 ++++++++++++++++++++++
2 files changed, 96 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-07-28 20:09:14 pgsql: Fix planner's nullability/strictness logic for ScalarArrayOpExpr
Previous Message Daniel Gustafsson 2026-07-28 19:58:40 pgsql: Handle invalid and dropped databases during checksum enable