From 0f448c346dc1f01850c81118cbbe8b62fcbf3c0d Mon Sep 17 00:00:00 2001
From: Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Date: Mon, 12 Oct 2026 08:02:37 +0000
Subject: [PATCH] Report standby replay progress before consistency

Standby mode currently suppresses WAL replay progress because recovery
can continue indefinitely.  This also hides progress while a standby is
still starting and has not yet reached consistency.

Enable the existing startup progress reporting during that bounded
interval.  Disable its timer as soon as consistency is reached,
preserving the existing behavior for normal long-running standby
replay.
---
 doc/src/sgml/config.sgml                  |  3 ++-
 src/backend/access/transam/xlogrecovery.c | 17 ++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index e537b3b0043..0ddca67e171 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7736,7 +7736,8 @@ 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.  During WAL replay on a standby server, progress is
+         reported only until the standby reaches a consistent recovery state.
          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 54aaec9529f..2d61db255da 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -427,12 +427,13 @@ EnableStandbyMode(void)
 	StandbyMode = true;
 
 	/*
-	 * To avoid server log bloat, we don't report recovery progress in a
-	 * standby as it will always be in recovery unless promoted. We disable
-	 * startup progress timeout in standby mode to avoid calling
-	 * startup_progress_timeout_handler() unnecessarily.
+	 * Report standby recovery progress only until consistency is reached.  If
+	 * redo has not started, disable any timeout left active by an earlier
+	 * startup phase; the redo phase will start its own timer.  If standby
+	 * mode is enabled during redo, keep the existing timer active.
 	 */
-	disable_startup_progress_timeout();
+	if (!InRedo || reachedConsistency)
+		disable_startup_progress_timeout();
 }
 
 /*
@@ -1715,7 +1716,7 @@ PerformWalRecovery(void)
 					   LSN_FORMAT_ARGS(xlogreader->ReadRecPtr)));
 
 		/* Prepare to report progress of the redo phase. */
-		if (!StandbyMode)
+		if (!StandbyMode || !reachedConsistency)
 			begin_startup_progress_phase();
 
 		/*
@@ -1723,7 +1724,7 @@ PerformWalRecovery(void)
 		 */
 		do
 		{
-			if (!StandbyMode)
+			if (!StandbyMode || !reachedConsistency)
 				ereport_startup_progress("redo in progress, elapsed time: %ld.%02d s, current LSN: %X/%08X",
 										 LSN_FORMAT_ARGS(xlogreader->ReadRecPtr));
 
@@ -2233,6 +2234,8 @@ CheckRecoveryConsistency(void)
 		CheckTablespaceDirectory();
 
 		reachedConsistency = true;
+		if (StandbyMode)
+			disable_startup_progress_timeout();
 		SendPostmasterSignal(PMSIGNAL_RECOVERY_CONSISTENT);
 		ereport(LOG,
 				errmsg("consistent recovery state reached at %X/%08X",
-- 
2.43.0

