From d56b6293009096ce64b30dd5ceddc35e768ac2f9 Mon Sep 17 00:00:00 2001
From: Simon Riggs <simon@2ndQuadrant.com>
Date: Wed, 5 Dec 2012 13:28:39 +0000
Subject: [PATCH] Must not reach consistency before XLOG_BACKUP_RECORD When
 waiting for an XLOG_BACKUP_RECORD the minRecoveryPoint will be incorrect, so
 we must not declare recovery as consistent before we have seen the record.
 Major bug allowing recovery to end too early in some cases, allowing people
 to see inconsistent db. This patch to HEAD and 9.2, other fix required for
 9.1 and 9.0

Simon Riggs and Andres Freund, bug report by Jeff Janes
---
 src/backend/access/transam/xlog.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 50e2b22dd70..187b60999e0 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7155,9 +7155,12 @@ CheckRecoveryConsistency(void)
 		return;
 
 	/*
-	 * Have we passed our safe starting point?
+	 * Have we passed our safe starting point? Note that minRecoveryPoint
+	 * is known to be incorrectly set if ControlFile->backupEndRequired,
+	 * until the XLOG_BACKUP_RECORD arrives to advise us of the correct
+	 * minRecoveryPoint. All we prior to that is its not consistent yet.
 	 */
-	if (!reachedConsistency &&
+	if (!reachedConsistency && !ControlFile->backupEndRequired &&
 		XLByteLE(minRecoveryPoint, EndRecPtr) &&
 		XLogRecPtrIsInvalid(ControlFile->backupStartPoint))
 	{
-- 
GitLab