postgres.git / summary / log / commit / refs

commit    4331d20f4d5cb51663b0912fdb2a3b991bc5a5c8
Author:   Masahiko Sawada <msawada@postgresql.org>
Date:     Mon Sep 28 23:28:33 2026 +0000
First released in: 19.0

    Fix crash in parallel autovacuum when no DSM segment can be created.
    
    If no DSM segment can be created, a ParallelContext can still be
    created with zero workers, but its seg pointer is NULL. Parallel
    autovacuum registered a segment detach callback on that NULL pointer,
    crashing the autovacuum worker.
    
    Fix by setting up the shared cost parameters and the detach callback
    only when the parallel context has workers, as there are no workers to
    propagate the parameters to otherwise.
    
    Oversight in commit 1ff3180ca01.
    
    Found by Bharath using AI assisted review with Claude.
    
    Reported-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
    Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
    Discussion: https://postgr.es/m/CALj2ACVjBN03Fq4XWgKH1zOfkapK6-P3ufNLHUHnZcW1zPm+Mg@mail.gmail.com
    Backpatch-through: 19


src/backend/commands/vacuumparallel.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c index 4532da60c84..d4572861000 100644 --- a/src/backend/commands/vacuumparallel.c +++ b/src/backend/commands/vacuumparallel.c @@ -458,9 +458,13 @@ parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes, /* * Initialize shared cost-based vacuum delay parameters if it's for - * autovacuum. + * autovacuum and the parallel context has workers. Note that the parallel + * context falls back to the leader's private memory with no workers and + * no segment when the maximum number of DSM segments has been reached. + * There are then no workers to propagate the parameters to, and no + * segment to register the detach callback on. */ - if (shared->is_autovacuum) + if (shared->is_autovacuum && pcxt->nworkers > 0) { parallel_vacuum_set_cost_parameters(&shared->cost_params); pg_atomic_init_u32(&shared->cost_params.generation, 1); [parent: 2b1d52b19799]