On 10/11/2025 18:38, Heikki Linnakangas wrote:
On 10/11/2025 17:16, Tom Lane wrote:
Heikki Linnakangas <[email protected]> writes:
Committed. Thanks for the quick review!
I think the number this should have bumped is PG_CONTROL_VERSION
(thanks to the new field therein). Bumping CATALOG_VERSION_NO
seems quite beside the point.
Ah thanks, I forgot we have that as a separate version number. I'll go
bump that now. (I will not try to revert the CATALOG_VERSION_NO change,
that would be very confusing.)
Fixed. And I just noticed another thing I forgot: pg_resetwal and
pg_controldata.
While testing, I noticed that pg_controldata doesn't check
PG_CONTROL_VERSION. If you add a field to ControlFileData that changes
the length, you'll get a warning that the CRC doesn't match:
pg_controldata: warning: calculated CRC checksum does not match value stored in
control file
pg_controldata: detail: Either the control file is corrupt, or it has a
different layout than this program is expecting. The results below are
untrustworthy.
but if you make any changes that *don't* change ControlFileData's size,
pg_controldata will merrily try to interpret the values with no warning.
Surely it should also check PG_CONTROL_VERSION?
- Heikki
From bcfc03715fd2d6b1b899ee66a3707409f9ced6c8 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <[email protected]>
Date: Mon, 10 Nov 2025 19:44:41 +0200
Subject: [PATCH 1/2] Add missing pg_resetwal and pg_control data support for
new field
I forgot these in commit 3e0ae46d90
---
src/bin/pg_controldata/pg_controldata.c | 2 ++
src/bin/pg_resetwal/pg_resetwal.c | 3 +++
2 files changed, 5 insertions(+)
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 10de058ce91..5c77f40313b 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -317,6 +317,8 @@ main(int argc, char *argv[])
ControlFile->blcksz);
printf(_("Blocks per segment of large relation: %u\n"),
ControlFile->relseg_size);
+ printf(_("Pages per SLRU segment: %u\n"),
+ ControlFile->slru_pages_per_segment);
printf(_("WAL block size: %u\n"),
ControlFile->xlog_blcksz);
printf(_("Bytes per WAL segment: %u\n"),
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index a89d72fc5cf..69a7cf0416d 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -697,6 +697,7 @@ GuessControlValues(void)
ControlFile.floatFormat = FLOATFORMAT_VALUE;
ControlFile.blcksz = BLCKSZ;
ControlFile.relseg_size = RELSEG_SIZE;
+ ControlFile.slru_pages_per_segment = SLRU_PAGES_PER_SEGMENT;
ControlFile.xlog_blcksz = XLOG_BLCKSZ;
ControlFile.xlog_seg_size = DEFAULT_XLOG_SEG_SIZE;
ControlFile.nameDataLen = NAMEDATALEN;
@@ -766,6 +767,8 @@ PrintControlValues(bool guessed)
ControlFile.blcksz);
printf(_("Blocks per segment of large relation: %u\n"),
ControlFile.relseg_size);
+ printf(_("Pages per SLRU segment: %u\n"),
+ ControlFile.slru_pages_per_segment);
printf(_("WAL block size: %u\n"),
ControlFile.xlog_blcksz);
printf(_("Bytes per WAL segment: %u\n"),
--
2.47.3
From 288af0403e003ff858e812238245380480c44e57 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <[email protected]>
Date: Mon, 10 Nov 2025 19:45:21 +0200
Subject: [PATCH 2/2] Add warning to pg_controldata on PG_CONTROL_VERSION
mismatch
---
src/bin/pg_controldata/pg_controldata.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 5c77f40313b..79f78d5fec9 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -167,7 +167,12 @@ main(int argc, char *argv[])
/* get a copy of the control file */
ControlFile = get_controlfile(DataDir, &crc_ok);
- if (!crc_ok)
+ if (ControlFile->pg_control_version != PG_CONTROL_VERSION)
+ {
+ pg_log_warning("control file's version does not match the version understood by this program");
+ pg_log_warning_detail("Either the control file is corrupt, or it has been created with a different version "
+ "of PostgreSQL. The results below are untrustworthy.");
+ } else if (!crc_ok)
{
pg_log_warning("calculated CRC checksum does not match value stored in control file");
pg_log_warning_detail("Either the control file is corrupt, or it has a different layout than this program "
--
2.47.3