• Tom Lane's avatar
    Avoid failure if autovacuum tries to access a just-dropped temp namespace. · 80d76be5
    Tom Lane authored
    Such an access became possible when commit 246a6c8f 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 a052f6cb.
    
    Backpatch as far as v11, as 246a6c8f was.
    
    Discussion: https://postgr.es/m/CAKYtNAr9Zq=1-ww4etHo-VCC-k120YxZy5OS01VkaLPaDbv2tg@mail.gmail.com
    80d76be5
autovacuum.c 99.1 KB