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 <[email protected]>
Author: ChangAo Chen <[email protected]>
Co-authored-by: Nathan Bossart <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Reviewed-by: Surya Poondla <[email protected]>
Reviewed-by: Bharath Rupireddy <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
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(-)

Reply via email to