pgsql: Avoid failure if autovacuum tries to access a just-dropped temp - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid failure if autovacuum tries to access a just-dropped temp
Date
Msg-id E1j7qw0-0004wb-Ab@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid failure if autovacuum tries to access a just-dropped temp namespace.

Such an access became possible when commit 246a6c8f7 added more
aggressive cleanup of orphaned temp relations by autovacuum.
Since autovacuum's snapshot might be slightly stale, it could
attempt to access an already-dropped temp namespace, resulting in
an assertion failure or null-pointer dereference.  (In practice,
since we don't drop temp namespaces automatically but merely
recycle them, this situation could only arise if a superuser does
a manual drop of a temp namespace.  Still, that should be allowed.)

The core of the bug, IMO, is that isTempNamespaceInUse and its callers
failed to think hard about whether to treat "temp namespace isn't there"
differently from "temp namespace isn't in use".  In hopes of forestalling
future mistakes of the same ilk, replace that function with a new one
checkTempNamespaceStatus, which makes the same tests but returns a
three-way enum rather than just a bool.  isTempNamespaceInUse is gone
entirely in HEAD; but just in case some external code is relying on it,
keep it in the back branches, as a bug-compatible wrapper around the
new function.

Per report originally from Prabhat Kumar Sahu, investigated by Mahendra
Singh and Michael Paquier; the final form of the patch is my fault.
This replaces the failed fix attempt in a052f6cbb.

Backpatch as far as v11, as 246a6c8f7 was.

Discussion: https://postgr.es/m/CAKYtNAr9Zq=1-ww4etHo-VCC-k120YxZy5OS01VkaLPaDbv2tg@mail.gmail.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d7684c38a5e9db15c205371528ea3686235229f4

Modified Files
--------------
src/backend/catalog/namespace.c     | 30 ++++++++++++++++++++----------
src/backend/postmaster/autovacuum.c |  7 ++++---
src/include/catalog/namespace.h     | 11 +++++++++++
3 files changed, 35 insertions(+), 13 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pgsql: Revert "initdb: Change authentication defaults"
Next
From: Peter Geoghegan
Date:
Subject: Re: pgsql: Add deduplication to nbtree.