On Tue, Jul 28, 2026 at 11:00 AM Masahiko Sawada <[email protected]> wrote:
>
> On Mon, Jul 27, 2026 at 6:00 PM Bharath Rupireddy
> <[email protected]> wrote:
> >
> > Hi,
> >
> > While working on the parallel heap vacuum feature I noticed a stale
> > comment in parallel_vacuum_main(). It says a parallel vacuum worker
> > must have only PROC_IN_VACUUM set because parallel index vacuum is not
> > supported for autovacuum. That is no longer true after commit
> > 1ff3180ca01, which enabled autovacuum to use parallel vacuum workers.
>
> Good catch!
>
> > IMHO, the assertion itself is still worth keeping. It ensures the
> > parallel worker carries PROC_IN_VACUUM, so that other backends ignore
> > its xmin when computing the removable-tuple horizon, which is what we
> > want for a worker that is part of a vacuum. The leader, whether it is
> > a backend running a VACUUM command or an autovacuum worker, sets
> > PROC_IN_VACUUM when it starts vacuuming the table, and the worker
> > inherits it when it imports the leader's snapshot (see
> > ProcArrayInstallRestoredXmin). PROC_IS_AUTOVACUUM never reaches the
> > worker, because parallel workers are launched as regular background
> > workers rather than autovacuum workers, so the flag is never set on
> > them, and importing the leader's snapshot doesn't carry it over
> > either. So the worker ends up with exactly PROC_IN_VACUUM even under
> > parallel autovacuum, and the assertion holds.
> >
> > The attached patch rewords the comment to explain this. Since PG19 is
> > still in beta, I would like to backpatch this to 19 where 1ff3180ca01
> > was introduced.
> >
> > Thoughts?
>
> I agree with your analysis. And the proposed comment looks clear to
> me. Will push the patch barring any objections.
>

After reviewing the new comment closely, I think it's better to
mention the PROC_VACUUM_FOR_WRAPAROUND flag too as this is also used
for autovacuums. I've attached the updated patch, please review it.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
From 28838cc1c8f640b837c7b35845ea97a5ea992d0e Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Mon, 27 Jul 2026 22:54:13 +0000
Subject: [PATCH v2] Fix stale comment in parallel_vacuum_main().

The comment claimed that a parallel vacuum worker has only the
PROC_IN_VACUUM flag because parallel vacuum is not supported for
autovacuum, but commit 1ff3180ca01 allowed autovacuum to use parallel
vacuum workers.

The assertion itself still holds: the leader, whether a backend
running VACUUM or an autovacuum worker, sets PROC_IN_VACUUM before
taking its snapshot, and a parallel worker inherits the flag when
importing the leader's snapshot. The leader's other flags don't reach
the worker, since the snapshot import copies only the PROC_XMIN_FLAGS
bits and PROC_IS_AUTOVACUUM is never set on parallel workers, which
run as regular background workers. Reword the comment to explain that.

Oversight in commit 1ff3180ca01.

Author: Bharath Rupireddy <[email protected]>
Discussion: https://postgr.es/m/CALj2ACVwQ4WABqq8Lnf+VZEJ45jcTFhyFLFr_ctfS4=qll-...@mail.gmail.com
Backpatch-through: 19
---
 src/backend/commands/vacuumparallel.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index 41cefcfde54..dd355a3d246 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -1209,8 +1209,16 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
 	ErrorContextCallback errcallback;
 
 	/*
-	 * A parallel vacuum worker must have only PROC_IN_VACUUM flag since we
-	 * don't support parallel vacuum for autovacuum as of now.
+	 * A parallel vacuum worker carries only the PROC_IN_VACUUM flag. The
+	 * leader, whether it's a backend running a VACUUM command or an
+	 * autovacuum worker, sets PROC_IN_VACUUM when it starts vacuuming the
+	 * table, and the worker inherits the flag by importing the leader's
+	 * snapshot (see ProcArrayInstallRestoredXmin). The leader's other flags
+	 * don't reach the worker: the snapshot import copies only the
+	 * PROC_XMIN_FLAGS bits, so PROC_VACUUM_FOR_WRAPAROUND isn't carried
+	 * over, and PROC_IS_AUTOVACUUM is never set on the worker in the first
+	 * place since parallel workers run as regular background workers, not
+	 * autovacuum workers.
 	 */
 	Assert(MyProc->statusFlags == PROC_IN_VACUUM);
 
-- 
2.54.0

Reply via email to