From e7d573bf8d3b832f196caf99765cb069956eb80c Mon Sep 17 00:00:00 2001
From: tomas <tomas>
Date: Sat, 30 Aug 2025 15:57:21 +0200
Subject: [PATCH v20251105 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 d70d0493dcb..1893396af85 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4447,6 +4447,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
@@ -4665,6 +4668,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);
 }
 
 /*
@@ -5569,6 +5575,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);
@@ -7338,7 +7347,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,
@@ -7354,7 +7363,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%%), "
@@ -7362,7 +7373,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,
@@ -7378,7 +7389,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)));
 }
 
 /*
@@ -7872,6 +7885,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
@@ -8019,6 +8035,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);
 
@@ -8364,6 +8383,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)

