From aeabd4262ae6467d7f1c7d22816f83360c9df906 Mon Sep 17 00:00:00 2001
From: Manu <manuelreyesbravo@gmail.com>
Date: Mon, 21 Sep 2026 20:53:25 -0300
Subject: [PATCH v4 3/6] Reset VACUUM's dead item progress counters after each
 index cycle

pg_stat_progress_vacuum documents num_dead_item_ids and dead_tuple_bytes
as what was collected since the last index vacuum cycle, but
dead_items_reset() emptied the dead item store without reporting it.
After each cycle the view kept showing the previous cycle's values until
the heap scan found the next page with dead items.

Before 667e65aac35 the same happened with num_dead_tuples, which was
documented the same way.

Found with the PROGRESS_DEBUG tracing proposed in the same thread.
---
 src/backend/access/heap/vacuumlazy.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 1f684b81f82..04530dcc6e2 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -3551,10 +3551,22 @@ dead_items_add(LVRelState *vacrel, BlockNumber blkno, OffsetNumber *offsets,
 static void
 dead_items_reset(LVRelState *vacrel)
 {
+	const int	prog_index[2] = {
+		PROGRESS_VACUUM_NUM_DEAD_ITEM_IDS,
+		PROGRESS_VACUUM_DEAD_TUPLE_BYTES
+	};
+	const int64 prog_val[2] = {0, 0};
+
 	/* Update statistics for dead items */
 	vacrel->num_dead_items_resets++;
 	vacrel->total_dead_items_bytes += TidStoreMemoryUsage(vacrel->dead_items);
 
+	/*
+	 * Both progress counters are documented as what was collected since the
+	 * last index vacuum cycle, which is nothing yet.
+	 */
+	pgstat_progress_update_multi_param(2, prog_index, prog_val);
+
 	if (ParallelVacuumIsActive(vacrel))
 	{
 		parallel_vacuum_reset_dead_items(vacrel->pvs);
-- 
2.55.0

