From 76e75797819d01e36b61ed3a74c51e821a5f2370 Mon Sep 17 00:00:00 2001 From: ChangAo Chen Date: Mon, 13 Apr 2026 20:51:55 +0800 Subject: [PATCH v1] Introduce GetEffectiveMinRecoveryPoint() If minRecoveryPoint is just after a xlog page header, we can move it to the begin of the page. It's safe because we just skip the xlog page header. Without this, it may take a long time to reach a consistent state (e.g. the primary doesn't have any xlog record after the minRecoveryPoint). --- src/backend/access/transam/xlogrecovery.c | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index c236e2b7969..63e8409eab9 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -2139,6 +2139,29 @@ CheckTablespaceDirectory(void) } } +/* + * If minRecoveryPoint is just after a xlog page header, we return a pointer + * that points to the begin of the page, otherwise return minRecoveryPoint. + * + * The returned pointer is used for checking whether we can reach a consistent + * state. It's safe because we just skip the xlog page header. + */ +static XLogRecPtr +GetEffectiveMinRecoveryPoint(void) +{ + XLogRecPtr ptr = minRecoveryPoint; + uint64 pageno = XLogSegmentOffset(ptr, wal_segment_size) / XLOG_BLCKSZ; + uint64 pageoff = ptr % XLOG_BLCKSZ; + + if (pageno == 0 && pageoff == SizeOfXLogLongPHD) + return ptr - SizeOfXLogLongPHD; + + if (pageno > 0 && pageoff == SizeOfXLogShortPHD) + return ptr - SizeOfXLogShortPHD; + + return ptr; +} + /* * Checks if recovery has reached a consistent state. When consistency is * reached and we have a valid starting standby snapshot, tell postmaster @@ -2199,7 +2222,7 @@ CheckRecoveryConsistency(void) * All we know prior to that is that we're not consistent yet. */ if (!reachedConsistency && !backupEndRequired && - minRecoveryPoint <= lastReplayedEndRecPtr) + GetEffectiveMinRecoveryPoint() <= lastReplayedEndRecPtr) { /* * Check to see if the XLOG sequence contained any unresolved -- 2.34.1