From fac6dfc4cdfef3302068420389e8aeeafc508014 Mon Sep 17 00:00:00 2001
From: tomas <tomas>
Date: Sat, 30 Aug 2025 15:57:21 +0200
Subject: [PATCH v20251006 2/2] Log checksum version during checkpoints etc.

log data_checksum_version, when:
- reading/writing the control file
- on every checkpoint
- setting ControlFile->data_checksum_version
---
 src/backend/access/transam/xlog.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 59f5cbe839f..1dbffd6097d 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4445,6 +4445,9 @@ WriteControlFile(void)
 				(errcode_for_file_access(),
 				 errmsg("could not close file \"%s\": %m",
 						XLOG_CONTROL_FILE)));
+
+	elog(LOG, "WriteControlFile ControlFile->data_checksum_version = %d ControlFile->checkPointCopy.data_checksum_version = %d",
+		 ControlFile->data_checksum_version, ControlFile->checkPointCopy.data_checksum_version);
 }
 
 static void
@@ -4663,6 +4666,9 @@ ReadControlFile(void)
 	elog(LOG, "ReadControlFile checkpoint %X/%08X redo %X/%08X",
 		 LSN_FORMAT_ARGS(ControlFile->checkPoint),
 		 LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo));
+
+	elog(LOG, "ReadControlFile ControlFile->data_checksum_version = %d ControlFile->checkPointCopy.data_checksum_version = %d",
+		 ControlFile->data_checksum_version, ControlFile->checkPointCopy.data_checksum_version);
 }
 
 /*
@@ -5567,6 +5573,9 @@ XLOGShmemInit(void)
 	/* Use the checksum info from control file */
 	XLogCtl->data_checksum_version = ControlFile->data_checksum_version;
 
+	elog(LOG, "XLOGShmemInit ControlFile->data_checksum_version = %d  ControlFile->checkPointCopy.data_checksum_version = %d",
+		 ControlFile->data_checksum_version, ControlFile->checkPointCopy.data_checksum_version);
+
 	SetLocalDataChecksumVersion(XLogCtl->data_checksum_version);
 
 	SpinLockInit(&XLogCtl->Insert.insertpos_lck);
@@ -7336,7 +7345,7 @@ LogCheckpointEnd(bool restartpoint)
 						"%d removed, %d recycled; write=%ld.%03d s, "
 						"sync=%ld.%03d s, total=%ld.%03d s; sync files=%d, "
 						"longest=%ld.%03d s, average=%ld.%03d s; distance=%d kB, "
-						"estimate=%d kB; lsn=%X/%08X, redo lsn=%X/%08X",
+						"estimate=%d kB; lsn=%X/%08X, redo lsn=%X/%08X, checksums=%d (%d)",
 						CheckpointStats.ckpt_bufs_written,
 						(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
 						CheckpointStats.ckpt_slru_written,
@@ -7352,7 +7361,9 @@ LogCheckpointEnd(bool restartpoint)
 						(int) (PrevCheckPointDistance / 1024.0),
 						(int) (CheckPointDistanceEstimate / 1024.0),
 						LSN_FORMAT_ARGS(ControlFile->checkPoint),
-						LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo))));
+						LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo),
+						ControlFile->data_checksum_version,
+						ControlFile->checkPointCopy.data_checksum_version)));
 	else
 		ereport(LOG,
 				(errmsg("checkpoint complete: wrote %d buffers (%.1f%%), "
@@ -7360,7 +7371,7 @@ LogCheckpointEnd(bool restartpoint)
 						"%d removed, %d recycled; write=%ld.%03d s, "
 						"sync=%ld.%03d s, total=%ld.%03d s; sync files=%d, "
 						"longest=%ld.%03d s, average=%ld.%03d s; distance=%d kB, "
-						"estimate=%d kB; lsn=%X/%08X, redo lsn=%X/%08X",
+						"estimate=%d kB; lsn=%X/%08X, redo lsn=%X/%08X, checksums=%d (%d)",
 						CheckpointStats.ckpt_bufs_written,
 						(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
 						CheckpointStats.ckpt_slru_written,
@@ -7376,7 +7387,9 @@ LogCheckpointEnd(bool restartpoint)
 						(int) (PrevCheckPointDistance / 1024.0),
 						(int) (CheckPointDistanceEstimate / 1024.0),
 						LSN_FORMAT_ARGS(ControlFile->checkPoint),
-						LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo))));
+						LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo),
+						ControlFile->data_checksum_version,
+						ControlFile->checkPointCopy.data_checksum_version)));
 }
 
 /*
@@ -7870,6 +7883,9 @@ CreateCheckPoint(int flags)
 	/* make sure we start with the checksum version as of the checkpoint */
 	ControlFile->data_checksum_version = checkPoint.data_checksum_version;
 
+	elog(LOG, "CreateCheckPoint ControlFile->data_checksum_version = %d ControlFile->checkPointCopy.data_checksum_version = %d",
+		 ControlFile->data_checksum_version, ControlFile->checkPointCopy.data_checksum_version);
+
 	/*
 	 * Persist unloggedLSN value. It's reset on crash recovery, so this goes
 	 * unused on non-shutdown checkpoints, but seems useful to store it always
@@ -8017,6 +8033,9 @@ CreateEndOfRecoveryRecord(void)
 	/* start with the latest checksum version (as of the end of recovery) */
 	ControlFile->data_checksum_version = XLogCtl->data_checksum_version;
 
+	elog(LOG, "CreateEndOfRecoveryRecord ControlFile->data_checksum_version = %d  ControlFile->checkPointCopy.data_checksum_version = %d",
+		 ControlFile->data_checksum_version, ControlFile->checkPointCopy.data_checksum_version);
+
 	UpdateControlFile();
 	LWLockRelease(ControlFileLock);
 
@@ -8362,6 +8381,9 @@ CreateRestartPoint(int flags)
 		/* we shall start with the latest checksum version */
 		ControlFile->data_checksum_version = lastCheckPoint.data_checksum_version;
 
+		elog(LOG, "CreateRestartPoint ControlFile->data_checksum_version = %d  ControlFile->checkPointCopy.data_checksum_version = %d",
+			 ControlFile->data_checksum_version, ControlFile->checkPointCopy.data_checksum_version);
+
 		UpdateControlFile();
 	}
 	LWLockRelease(ControlFileLock);
-- 
2.39.3 (Apple Git-146)

