diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 49ae97d4459..0fbdf6fd64a 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -8365,7 +8365,7 @@ CheckRecoveryConsistency(void)
 	 * run? If so, we can tell postmaster that the database is consistent now,
 	 * enabling connections.
 	 */
-	if (standbyState == STANDBY_SNAPSHOT_READY &&
+	if ((standbyState == STANDBY_SNAPSHOT_READY || standbyState == STANDBY_SNAPSHOT_PENDING) &&
 		!LocalHotStandbyActive &&
 		reachedConsistency &&
 		IsUnderPostmaster)
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 448d1eadfb8..c26cdfb9a9b 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -96,6 +96,12 @@ typedef struct ProcArrayStruct
 	/* oldest catalog xmin of any replication slot */
 	TransactionId replication_slot_catalog_xmin;
 
+	/*
+	 * If oldest_running_xmin is valid value, then we assume oldest_running_xmin <= xid < xmax is still running.
+	 * When standbyState is switched to STANDBY_SNAPSHOT_PENDING, we initialize oldest_running_xmin with oldestRunningXid.
+	 * When we have full knowledge of transactions that are running, we set oldest_running_xmin to be InvalidTransactionId.
+	 */
+	TransactionId oldest_running_xmin;
 	/* indexes into allPgXact[], has PROCARRAY_MAXPROCS entries */
 	int			pgprocnos[FLEXIBLE_ARRAY_MEMBER];
 } ProcArrayStruct;
@@ -870,12 +876,14 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
 
 		standbySnapshotPendingXmin = latestObservedXid;
 		procArray->lastOverflowedXid = latestObservedXid;
+		procArray->oldest_running_xmin = running->oldestRunningXid;
 	}
 	else
 	{
 		standbyState = STANDBY_SNAPSHOT_READY;
 
 		standbySnapshotPendingXmin = InvalidTransactionId;
+		procArray->oldest_running_xmin = InvalidTransactionId;
 	}
 
 	/*
@@ -1708,6 +1716,9 @@ GetSnapshotData(Snapshot snapshot)
 		 * those newly added transaction ids would be filtered away, so we
 		 * need not be concerned about them.
 		 */
+		if (procArray->oldest_running_xmin != InvalidTransactionId
+				&& TransactionIdPrecedes(procArray->oldest_running_xmin, xmin))
+			xmin = procArray->oldest_running_xmin;
 		subcount = KnownAssignedXidsGetAndSetXmin(snapshot->subxip, &xmin,
 												  xmax);
 
