0001-Modified-the-condition-to-ignore-shutdown-only-check.patch

text/x-patch

Filename: 0001-Modified-the-condition-to-ignore-shutdown-only-check.patch
Type: text/x-patch
Part: 1
Message: Re: [PATCH] Fix pg_rewind false positives caused by shutdown-only WAL

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0001
Subject: Modified the condition to ignore shutdown-only checkpoints to avoid pg_rewind false positives caused by shutdown
File+
src/bin/pg_rewind/parsexlog.c 29 7
From 44d0b45aa40d3fb0bc2b4907b277f321417dbc98 Mon Sep 17 00:00:00 2001
From: manimurali1993 <manimurali1993@gamil.com>
Date: Tue, 23 Sep 2025 16:24:11 +0530
Subject: [PATCH] Modified the condition to ignore shutdown-only checkpoints to
 avoid pg_rewind false positives caused by shutdown

Signed-off-by: manimurali1993 <manimurali1993@gamil.com>
---
 src/bin/pg_rewind/parsexlog.c | 36 ++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c
index 8f4b282c6b1..af1fd474f6c 100644
--- a/src/bin/pg_rewind/parsexlog.c
+++ b/src/bin/pg_rewind/parsexlog.c
@@ -249,13 +249,35 @@ findLastCheckpoint(const char *datadir, XLogRecPtr forkptr, int tliIndex,
 			(info == XLOG_CHECKPOINT_SHUTDOWN ||
 			 info == XLOG_CHECKPOINT_ONLINE))
 		{
-			CheckPoint	checkPoint;
-
-			memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
-			*lastchkptrec = searchptr;
-			*lastchkpttli = checkPoint.ThisTimeLineID;
-			*lastchkptredo = checkPoint.redo;
-			break;
+			if (searchptr < forkptr &&
++           XLogRecGetRmid(xlogreader) == RM_XLOG_ID)
+			{
+				CheckPoint	checkPoint;
+
+				memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
+				*lastchkptrec = searchptr;
+				*lastchkpttli = checkPoint.ThisTimeLineID;
+				*lastchkptredo = checkPoint.redo;
+				break;
+				if (info == XLOG_CHECKPOINT_ONLINE)
+				{
+					CheckPoint   checkPoint;
+
+               		memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
+               		*lastchkptrec = searchptr;
+               		*lastchkpttli = checkPoint.ThisTimeLineID;
+               		*lastchkptredo = checkPoint.redo;
+               		break;
+				}
+				else if (info == XLOG_CHECKPOINT_SHUTDOWN)
+				{
+					/*
+					 * Skip shutdown-only checkpoints, since they don't represent
+					 * real divergence. Keep scanning further back.
+					 */
+					continue;
+				}
+			}
 		}
 
 		/* Walk backwards to previous record. */
-- 
2.34.1