pgsql: Fix DROP DATABASE FORCE failing on parallel autovacuum workers.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix DROP DATABASE FORCE failing on parallel autovacuum workers.
Date: 2026-10-15 17:34:00
Message-ID: E1xHPL6-00000001lN1-2hS5@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix DROP DATABASE FORCE failing on parallel autovacuum workers.

An autovacuum worker advertises no role in its PGPROC, but its
parallel workers advertise the bootstrap superuser. So DROP DATABASE
... FORCE run by a non-superuser with pg_signal_backend failed with
"permission denied to terminate process" while a parallel autovacuum
was running in the database, although the same user can terminate the
autovacuum worker itself, and DROP DATABASE without FORCE succeeds.

Fix by checking a parallel worker against its leader's role when the
leader advertises no role. The leader is in the same database and is
checked too, so this doesn't let anyone terminate a process they
couldn't already terminate through its leader.

Parallel workers launched by a background worker connected without a
user name have had the same problem in older branches, but we haven't
received any report of it, and the next minor release is the final one
for v14, leaving no chance to fix a mistake there. So backpatch only
to v19, where parallel autovacuum made the problem easy to hit. If we
get a report, we can backpatch it further.

Found by Bharath using AI assisted review.

Reported-by: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Author: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: shihao zhong <zhong950419(at)gmail(dot)com>
Discussion: https://postgr.es/m/CALj2ACWK6PkOk5MTfibtJyTYpb=Aq_8=YaexnPKhOj11bOCROQ@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2761a3c351ba7424e46a8452a99a0839edc418c7

Modified Files
--------------
src/backend/commands/vacuumparallel.c | 4 +++
src/backend/storage/ipc/procarray.c | 25 ++++++++++---
.../test_autovacuum/t/001_parallel_autovacuum.pl | 42 ++++++++++++++++++++++
3 files changed, 67 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-10-15 18:45:37 pgsql: Install infrastructure to manage psql's hidden query labels bett
Previous Message Masahiko Sawada 2026-10-15 17:33:56 pgsql: Fix DROP DATABASE FORCE failing on parallel autovacuum workers.