aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xlog.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 290278e0d33..518e769faa0 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7973,13 +7973,6 @@ StartupXLOG(void)
/* Reload shared-memory state for prepared transactions */
RecoverPreparedTransactions();
- /*
- * Shutdown the recovery environment. This must occur after
- * RecoverPreparedTransactions(), see notes for lock_twophase_recover()
- */
- if (standbyState != STANDBY_DISABLED)
- ShutdownRecoveryTransactionEnvironment();
-
/* Shut down xlogreader */
if (readFile >= 0)
{
@@ -8029,6 +8022,18 @@ StartupXLOG(void)
LWLockRelease(ControlFileLock);
/*
+ * Shutdown the recovery environment. This must occur after
+ * RecoverPreparedTransactions() (see notes in lock_twophase_recover())
+ * and after switching SharedRecoveryState to RECOVERY_STATE_DONE so as
+ * any session building a snapshot will not rely on KnownAssignedXids as
+ * RecoveryInProgress() would return false at this stage. This is
+ * particularly critical for prepared 2PC transactions, that would still
+ * need to be included in snapshots once recovery has ended.
+ */
+ if (standbyState != STANDBY_DISABLED)
+ ShutdownRecoveryTransactionEnvironment();
+
+ /*
* If there were cascading standby servers connected to us, nudge any wal
* sender processes to notice that we've been promoted.
*/