diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 6fa5479..75be478 100755
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -10935,10 +10935,13 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 					curFileTLI = 0;
 
 				/*
-				 * Try to restore the file from archive, or read an existing
-				 * file from pg_xlog.
+				 * When XLOG_FROM_ARCHIVE, read xlog file with largest TLI
+				 * preferring archive to pg_xlog. Or when XLOG_FROM_PG_XLOG,
+				 * search only pg_xlog.
 				 */
-				readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2, currentSource);
+				readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2,
+									currentSource == XLOG_FROM_ARCHIVE ?
+									XLOG_FROM_ANY : currentSource);
 				if (readFile >= 0)
 					return true;	/* success! */
 
