1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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 1ff3180ca0.

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
This commit is contained in:
Masahiko Sawada
2026-09-28 16:28:30 -07:00
parent d9b5a63f49
commit cc053b6e12

View File

@@ -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);