0001-Adjust-logging-for-invalid-recovery-timeline.patch

text/x-patch

Filename: 0001-Adjust-logging-for-invalid-recovery-timeline.patch
Type: text/x-patch
Part: 0
Message: Re: Fix logging for invalid recovery timeline

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: Adjust logging for invalid recovery timeline
File+
src/backend/access/transam/xlogrecovery.c 16 7
From 44459bf799fca517b13aef03be952b0374463d5c Mon Sep 17 00:00:00 2001
From: benoit <benoit.lobreau@dalibo.com>
Date: Fri, 21 Feb 2025 14:09:56 +0100
Subject: [PATCH] Adjust logging for invalid recovery timeline

The original message doesn't mention where the checkpoint was read from.
It refers to the "Latest checkpoint", the terminology is used for some
records from the control file (specifically, the pg_controldata output).
The backup label uses "Checkpoint location".
---
 src/backend/access/transam/xlogrecovery.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index f234007d348..7ada300bf9b 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -846,13 +846,22 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
 		 * not in expectedTLEs at all.
 		 */
 		switchpoint = tliSwitchPoint(CheckPointTLI, expectedTLEs, NULL);
-		ereport(FATAL,
-				(errmsg("requested timeline %u is not a child of this server's history",
-						recoveryTargetTLI),
-				 errdetail("Latest checkpoint is at %X/%X on timeline %u, but in the history of the requested timeline, the server forked off from that timeline at %X/%X.",
-						   LSN_FORMAT_ARGS(CheckPointLoc),
-						   CheckPointTLI,
-						   LSN_FORMAT_ARGS(switchpoint))));
+		if (haveBackupLabel)
+			ereport(FATAL,
+					(errmsg("requested timeline %u is not a child of this server's history",
+							recoveryTargetTLI),
+					 errdetail("The checkpoint location in the backup_label file is at %X/%X on timeline %u, but in the history of the requested timeline, the server forked off from that timeline at %X/%X.",
+							   LSN_FORMAT_ARGS(CheckPointLoc),
+							   CheckPointTLI,
+							   LSN_FORMAT_ARGS(switchpoint))));
+		else
+			ereport(FATAL,
+					(errmsg("requested timeline %u is not a child of this server's history",
+							recoveryTargetTLI),
+					 errdetail("The latest checkpoint in the control file is at %X/%X on timeline %u, but in the history of the requested timeline, the server forked off from that timeline at %X/%X.",
+							   LSN_FORMAT_ARGS(CheckPointLoc),
+							   CheckPointTLI,
+							   LSN_FORMAT_ARGS(switchpoint))));
 	}
 
 	/*
-- 
2.48.1