Re: "could not open relation 1663/16384/16584: No such file or directory" in a specific combination of transactions with temp tables - Mailing list pgsql-hackers

From Tom Lane
Subject Re: "could not open relation 1663/16384/16584: No such file or directory" in a specific combination of transactions with temp tables
Date
Msg-id 5011.1204409077@sss.pgh.pa.us
Whole thread Raw
In response to Re: "could not open relation 1663/16384/16584: No such file or directory" in a specific combination of transactions with temp tables  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: "could not open relation 1663/16384/16584: No such file or directory" in a specific combination of transactions with temp tables
List pgsql-hackers
I wrote:
> This explanation is nonsense; we certainly *are* holding a lock on any
> relation that's about to be dropped.  Experimentation shows that
> AccessExclusiveLock is indeed held (you can see it in pg_locks), but
> nonetheless the PREPARE doesn't complain.  Did you trace through
> exactly why?

I looked into this, and the problem is in LockTagIsTemp: it checks
whether a lock is on a temp table this way:
           if (isTempOrToastNamespace(get_rel_namespace((Oid) tag->locktag_field2)))               return true;

What is happening is that get_rel_namespace fails to find the syscache
entry for the table's pg_class row (which is expected since it's already
been deleted as far as this transaction is concerned).  It silently
returns InvalidOid, and then isTempOrToastNamespace returns false,
and so we mistakenly conclude the lock is not on a temp object.

This coding had bothered me all along because I didn't care for doing a
lot of syscache lookups during transaction commit, but I hadn't realized
that it was outright wrong.

I think we need some better means of recording whether a lock is on a
temp object.  We could certainly add a flag to the LOCALLOCK struct,
but it's not clear where a clean place to set it would be.  As a rule
we don't yet know when locking a relation whether it's temp or not.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: "could not open relation 1663/16384/16584: No such file or directory" in a specific combination of transactions with temp tables
Next
From: "Gurjeet Singh"
Date:
Subject: Fwd: "could not open relation 1663/16384/16584: No such file or directory" in a specific combination of transactions with temp tables