Hi,

I noticed that two of the parallel vacuum's shared memory pointers
(VacuumSharedCostBalance and VacuumActiveNWorkers) are not reset on
the error path, leaving them dangling, that is, pointing to a shared
memory segment that is already gone, until the next vacuum runs in the
backend or autovacuum worker. This doesn't cause any issue today, but
IMHO it is good practice to avoid dangling pointers.

Please find the attached patch that sets them to NULL on the error
path (the normal path resets them in
parallel_vacuum_process_all_indexes()).

Thoughts?

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
From b8fec346077fb56ace609b0f3f3bb4994fcc2d97 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Tue, 13 Oct 2026 21:39:01 +0000
Subject: [PATCH v1] Avoid dangling shared memory pointers in parallel vacuum

This commit resets VacuumSharedCostBalance, VacuumActiveNWorkers
and VacuumCostBalanceLocal when vacuum ends with an error, as they
otherwise stay dangling until the next vacuum resets them.

Author: Bharath Rupireddy <[email protected]>
Discussion: https://postgr.es/m/<message-id>
---
 src/backend/commands/vacuum.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index a257dd8d21e..c7595d59bb2 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -684,6 +684,9 @@ vacuum(List *relations, const VacuumParams *params, BufferAccessStrategy bstrate
 		VacuumCostActive = false;
 		VacuumFailsafeActive = false;
 		VacuumCostBalance = 0;
+		VacuumCostBalanceLocal = 0;
+		VacuumSharedCostBalance = NULL;
+		VacuumActiveNWorkers = NULL;
 	}
 	PG_END_TRY();
 
-- 
2.47.3

Reply via email to