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:58:40
Message-ID: E1wonwm-00000000hfi-1LZT@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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/153ca22a3a71ccaa55f27a4686202bce8f8de759

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 Daniel Gustafsson 2026-07-28 19:59:30 pgsql: Recheck checksum state before file_copy during CREATE DATABASE
Previous Message Masahiko Sawada 2026-07-28 19:35:03 pgsql: Fix logical decoding of empty prepared transactions.