agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Subject: [PATCH v1 3/4] Apply the same timeline fix to read_local_xlog_page_guts()
Date: Mon, 8 Jun 2026 07:04:43 +0000

read_local_xlog_page_guts() has the same race as logical_read_xlog_page() (that
has been fixed in commit xxxxx): when RecoveryInProgress() returns true during
promotion, it gets the old timeline from GetXLogReplayRecPtr() while old WAL
segments may already be removed.

This affects SQL-callable logical decoding functions (pg_logical_slot_get_changes,
pg_logical_slot_peek_changes) running on a standby during promotion.

Apply the same fix: use GetWALInsertionTimeLineIfSet() to detect that the
insertion timeline is already established and use it directly.

Reported-by: Xuneng Zhou <xunengzhou@gmail.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by:
Discussion: https://postgr.es/m/7daef094-abf3-4672-bc23-3df4763b16a3%40gmail.com
---
 src/backend/access/transam/xlogutils.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 100.0% src/backend/access/transam/

diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index 5fbe39133b8..fdc341d8fa4 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -896,7 +896,19 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr,
 		if (!RecoveryInProgress())
 			read_upto = GetFlushRecPtr(&currTLI);
 		else
+		{
+			TimeLineID	insertTLI;
+
 			read_upto = GetXLogReplayRecPtr(&currTLI);
+
+			/*
+			 * If the insertion timeline has already been set, use it. See
+			 * logical_read_xlog_page() for details.
+			 */
+			insertTLI = GetWALInsertionTimeLineIfSet();
+			if (insertTLI != 0)
+				currTLI = insertTLI;
+		}
 		tli = currTLI;
 
 		/*
-- 
2.34.1


--HitlKQoyB8givWgr
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v1-0004-Add-SQL-path-test-for-read_local_xlog_page_guts-t.patch"



view thread (739+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: bertranddrouvot.pg@gmail.com
  Subject: Re: [PATCH v1 3/4] Apply the same timeline fix to read_local_xlog_page_guts()
  In-Reply-To: <no-message-id-597732@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox