diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 6876537b62..61b235f8f7 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -11881,10 +11881,12 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 					 * obtaining the requested WAL. We're going to loop back
 					 * and retry from the archive, but if it hasn't been long
 					 * since last attempt, sleep wal_retrieve_retry_interval
-					 * milliseconds to avoid busy-waiting.
+					 * milliseconds to avoid busy-waiting. We don't wait if
+					 * explicitly requested to restart.
 					 */
 					now = GetCurrentTimestamp();
-					if (!TimestampDifferenceExceeds(last_fail_time, now,
+					if (!pendingWalRcvRestart &&
+						!TimestampDifferenceExceeds(last_fail_time, now,
 													wal_retrieve_retry_interval))
 					{
 						long		secs,
@@ -11905,6 +11907,17 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 					}
 					last_fail_time = now;
 					currentSource = XLOG_FROM_ARCHIVE;
+
+					/*
+					 * If wal receiver is requested to restart, we skip the
+					 * next XLOG_FROM_ARCHIVE to immediately starting it.
+					 */
+					if (pendingWalRcvRestart)
+					{
+						lastSourceFailed = true;
+						continue;
+					}
+
 					break;
 
 				default:
