From da26d6c92b73168b80ae7c4cf6da9ab4e96efe2c Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Thu, 13 Aug 2026 11:48:16 +0200 Subject: [PATCH v4 1/2] Record initial state of data checksums in controlfile The controlfile records the current state of data checksums, which also used to be the initial state from initdb when checksums could not be altered after initialization. pg_control_init is documented to return information about cluster initialization state, which it no longer will if data checksums have been changed either using the offline tool or with online processing. Fix by adding a new field in the control file which tracks the init value of data checksums, and is left read only after initialization. While this is a regression dating back to when changing checksum state was made possible offline with pg_checksums, it is a control file change so it cannot be backpatched. Backpatch to v19 where online checksums were introduced. Author: Daniel Gustafsson Reviewed-by: ... Discussion: ... Backpatch-through: 19 --- src/backend/access/transam/xlog.c | 1 + src/backend/utils/misc/pg_controldata.c | 2 +- src/include/catalog/pg_control.h | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b23d8bbbdad..40bee3a71bc 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -4283,6 +4283,7 @@ InitControlFile(uint64 sysidentifier, uint32 data_checksum_version) ControlFile->wal_log_hints = wal_log_hints; ControlFile->track_commit_timestamp = track_commit_timestamp; ControlFile->data_checksum_version = data_checksum_version; + ControlFile->data_checksum_version_init = data_checksum_version; /* * Set the data_checksum_version value into XLogCtl, which is where all diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c index d229ae35209..d4feec95b26 100644 --- a/src/backend/utils/misc/pg_controldata.c +++ b/src/backend/utils/misc/pg_controldata.c @@ -254,7 +254,7 @@ pg_control_init(PG_FUNCTION_ARGS) values[9] = BoolGetDatum(ControlFile->float8ByVal); nulls[9] = false; - values[10] = Int32GetDatum(ControlFile->data_checksum_version); + values[10] = Int32GetDatum(ControlFile->data_checksum_version_init); nulls[10] = false; values[11] = BoolGetDatum(ControlFile->default_char_signedness); diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h index 80b3a730e03..34ce857b38f 100644 --- a/src/include/catalog/pg_control.h +++ b/src/include/catalog/pg_control.h @@ -22,7 +22,7 @@ /* Version identifier for this pg_control format */ -#define PG_CONTROL_VERSION 1902 +#define PG_CONTROL_VERSION 1903 /* Nonce key length, see below */ #define MOCK_AUTH_NONCE_LEN 32 @@ -228,7 +228,9 @@ typedef struct ControlFileData bool float8ByVal; /* float8, int8, etc pass-by-value? */ - /* Are data pages protected by checksums? Zero if no checksum version */ + /* Are data pages initialized to be protected by checksums? */ + uint32 data_checksum_version_init; + /* Are data pages currently by checksums? Zero if no checksum version */ uint32 data_checksum_version; /* -- 2.39.3 (Apple Git-146)