From 63e936e2b74bd1931e5a4fd14325b0ca6aae8bb1 Mon Sep 17 00:00:00 2001
From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Date: Wed, 4 Nov 2026 19:09:21 -0300
Subject: [PATCH v1] Reset lockers progress columns at end of
 WaitForOlderSnapshots()

WaitForOlderSnapshots() reports lockers_total, lockers_done and
current_locker_pid while it waits, but left them set when done, unlike
WaitForLockersMultiple(), which resets all three at the end of its
wait.  As both only set lockers_total when they start, the next wait
inherited the other two: during the wait for readers that follows the
last wait for old snapshots in REINDEX CONCURRENTLY,
pg_stat_progress_create_index could show lockers_done greater than
lockers_total.  current_locker_pid also kept the PID of a transaction
that was no longer waited for, until the next wait or the end of the
command.  The documentation says these columns contain the progress
information of the current phase.

Reset the three columns at the end of WaitForOlderSnapshots(), the
same way as WaitForLockersMultiple().

Oversight in commit ab0dfc961b6.
---
 src/backend/commands/indexcmds.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 5a0312fe772..c67176b487a 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -507,6 +507,20 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
 		if (progress)
 			pgstat_progress_update_param(PROGRESS_WAITFOR_DONE, i + 1);
 	}
+
+	if (progress)
+	{
+		const int	index[] = {
+			PROGRESS_WAITFOR_TOTAL,
+			PROGRESS_WAITFOR_DONE,
+			PROGRESS_WAITFOR_CURRENT_PID
+		};
+		const int64 values[] = {
+			0, 0, 0
+		};
+
+		pgstat_progress_update_multi_param(3, index, values);
+	}
 }
 
 
-- 
2.56.0

