agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Handle concurrently-dropped relations in database-wide VACUUM.
Date: Mon, 03 Aug 2026 21:03:07 +0000
Message-ID: <E1wqzoR-000000003vW-3o6V@gemulon.postgresql.org> (raw)

Handle concurrently-dropped relations in database-wide VACUUM.

When VACUUM or ANALYZE is run without a table list, we scan
pg_class to build the list of relations to process, and we
check the privileges on each relation we find.  Since we don't
take any locks on the relations at this point, it's possible
for one to be concurrently dropped, in which case the privilege
check fails with an ERROR such as the following:

        ERROR:  relation with OID 16388 does not exist

This unnecessarily aborts the entire command.  To fix, use
pg_class_aclcheck_ext() for the privilege check so that we can
detect concurrently-dropped relations and silently skip them.
There's no need to emit a WARNING for such relations because
they weren't explicitly named, and a drop at this point is no
different than one that happened before our pg_class scan
began.  Note that concurrent drops that occur later on are
already handled gracefully by vacuum_open_relation().

The new missing_ok behavior is limited to get_all_vacuum_rels().
All other callers of vacuum_is_permitted_for_relation() should
hold a lock on the relation that prevents it from being
concurrently dropped, so this commit also adds an assertion to
that effect.

Oversight in commit a556549d7e.

This is a bug fix and could be back-patched, but given the
presumed rarity of the race condition and the lack of field
reports, I'm not going to bother.

Reported-by: ChangAo Chen <cca5507@qq.com>
Author: ChangAo Chen <cca5507@qq.com>
Co-authored-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Surya Poondla <suryapoondla4@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/tencent_F9D483523BB0D082C2EFDA80142F192DBC07%40qq.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/824d5f6241ea7a0a85c9d2b3d27beb78e42a36ab

Modified Files
--------------
src/backend/commands/analyze.c |  3 ++-
src/backend/commands/vacuum.c  | 29 ++++++++++++++++++++++++-----
src/include/commands/vacuum.h  |  2 +-
3 files changed, 27 insertions(+), 7 deletions(-)



Message-ID: <E1wqzoR-000000003vW-3o6V@gemulon.postgresql.org>
Permalink:  ../E1wqzoR-000000003vW-3o6V@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wqzoR-000000003vW-3o6V@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: nathan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Handle concurrently-dropped relations in database-wide VACUUM.
  In-Reply-To: <E1wqzoR-000000003vW-3o6V@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox