From 36b272b949dba2b54b22305ee1bd2cfdf17f8451 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
Date: Thu, 11 Jun 2026 08:28:12 +0900
Subject: [PATCH v3 2/2] Disable startup progress timeout during standby WAL
 replay

The startup process could wake up periodically during standby WAL
replay even though it did not report replay progress. These wakeups
served no purpose and could continue until promotion.

This happened because startup operations such as
ResetUnloggedRelations() could re-enable the startup progress timeout
after EnableStandbyMode() had disabled it. The timeout then remained
active when WAL replay began in standby mode.

Fix this by disabling the timeout again before reading the first WAL
record if standby mode is already active. This preserves progress
reporting for earlier startup operations and avoids unnecessary timeout
activity while waiting for the first record to become available.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Reviewed-by: Aidar Imamov <imamovaj22@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwFJixYTymPZ6dwOO-G0VdjO1AgZTma6CtJgc0Ptxfz3BA@mail.gmail.com
---
 doc/src/sgml/config.sgml                  |  5 ++++-
 src/backend/access/transam/xlogrecovery.c | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 886e8c44847..1b2f08eb23d 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7791,7 +7791,10 @@ local0.*    /var/log/postgresql
          operation. The default is 10 seconds. A setting of <literal>0</literal>
          disables the feature.  If this value is specified without units,
          it is taken as milliseconds.  This setting is applied separately to
-         each operation.
+         each operation, such as WAL replay, syncing the data directory,
+         and resetting unlogged relations.  WAL replay progress is not
+         reported in standby mode, but may be reported during crash recovery
+         before entering standby mode.
          This parameter can only be set in the <filename>postgresql.conf</filename>
          file or on the server command line.
         </para>
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index e091a3e178b..6fa820c2caf 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -1677,6 +1677,17 @@ PerformWalRecovery(void)
 	 */
 	CheckRecoveryConsistency();
 
+	/*
+	 * If already in standby mode, disable the startup progress timeout again,
+	 * since startup operations such as ResetUnloggedRelations() may have
+	 * re-enabled it after EnableStandbyMode().  WAL replay progress is not
+	 * reported in standby mode, so disable the timeout before reading the
+	 * first WAL record, which may require waiting for WAL to become
+	 * available.
+	 */
+	if (StandbyMode)
+		disable_startup_progress_timeout();
+
 	/*
 	 * Find the first record that logically follows the checkpoint --- it
 	 * might physically precede it, though.
-- 
2.56.0

