From baa752e1a27191848a20299fd0fc2e0b0b62fc93 Mon Sep 17 00:00:00 2001
From: Stepan Neretin <slpmcf@gmail.com>
Date: Tue, 17 Nov 2026 02:12:33 +0700
Subject: [PATCH 1/2] Remove bogus Assert in pg_rewind ancestor check

If the target is a direct ancestor of the source, its WAL may end
before the divergence LSN, for example after an older base backup of
the primary.  Assert "target_wal_endrec == divergerec" then crashes
assertion builds.  Otherwise we already report that no rewind is
required.

Drop the Assert.
---
 src/bin/pg_rewind/pg_rewind.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index d2521dab333..fd5c0e031db 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -452,9 +452,11 @@ main(int argc, char **argv)
 		}
 		else
 		{
-			/* the last common checkpoint record must be part of target WAL */
-			Assert(target_wal_endrec == divergerec);
-
+			/*
+			 * Target stopped at or before the divergence point, so it is
+			 * an ancestor and needs no rewind.  Stopping earlier is fine
+			 * too, for example after an older base backup of the primary.
+			 */
 			rewind_needed = false;
 		}
 	}
-- 
2.56.0

