From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 26 Nov 2021 14:14:27 +0000 (-0300)
Subject: Fix determination of broken LSN in OVERWRITTEN_CONTRECORD
X-Git-Tag: REL_10_20~60
X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=72cf39d51ade63954c868bfe93996b4be7a79bf5;p=postgresql.git

Fix determination of broken LSN in OVERWRITTEN_CONTRECORD

In commit ff9f111bce24 I mixed up inconsistent definitions of the LSN of
the first record in a page, when the previous record ends exactly at the
page boundary.  The correct LSN is adjusted to skip the WAL page header;
I failed to use that when setting XLogReaderState->overwrittenRecPtr,
so at WAL replay time VerifyOverwriteContrecord would refuse to let
replay continue past that record.

Backpatch to 10.  9.6 also contains this bug, but it's no longer being
maintained.

Discussion: https://postgr.es/m/45597.1637694259@sss.pgh.pa.us
---

diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 456cdab461e..6e574b8df9b 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -412,7 +412,7 @@ restart:
 			 */
 			if (pageHeader->xlp_info & XLP_FIRST_IS_OVERWRITE_CONTRECORD)
 			{
-				state->overwrittenRecPtr = state->currRecPtr;
+				state->overwrittenRecPtr = RecPtr;
 				ResetDecoder(state);
 				RecPtr = targetPagePtr;
 				goto restart;