On 2/20/25 4:40 PM, David Steele wrote:
Benoit -- this was your idea. Did you want to submit a patch yourself?

Here is an attempt at that. I kept the wording I used above. Is it fine to repeat the whole ereport block twice?

--
Benoit Lobréau
Consultant
http://dalibo.com
From 44459bf799fca517b13aef03be952b0374463d5c Mon Sep 17 00:00:00 2001
From: benoit <benoit.lobr...@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

Reply via email to