diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c index c624f9163a1..4fd11e66284 100644 --- a/src/backend/access/transam/xlogwait.c +++ b/src/backend/access/transam/xlogwait.c @@ -488,11 +488,19 @@ WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN, int64 timeout) if (WaitLSNTypeRequiresRecovery(lsnType) && !RecoveryInProgress()) { /* - * Recovery was ended, but check if target LSN was already + * Recovery has ended, but check if target LSN was already * reached. */ deleteLSNWaiter(lsnType); + /* + * Recovery may have advanced the current position after + * currentLSN was read above. Once RecoveryInProgress() returns + * false, the final position is stable, so read it again before + * deciding whether promotion reached the target. + */ + currentLSN = GetCurrentLSNForWaitType(lsnType); + if (PromoteIsTriggered() && targetLSN <= currentLSN) return WAIT_LSN_RESULT_SUCCESS; return WAIT_LSN_RESULT_NOT_IN_RECOVERY;