Re: strange error with temp table: pg_type_typname_nsp_index - Mailing list pgsql-general

From Tom Lane
Subject Re: strange error with temp table: pg_type_typname_nsp_index
Date
Msg-id 20813.1121361524@sss.pgh.pa.us
Whole thread Raw
In response to strange error with temp table: pg_type_typname_nsp_index  (Janning Vygen <vygen@gmx.de>)
List pgsql-general
Janning Vygen <vygen@planwerk6.de> writes:
>    PERFORM n.nspname ,c.relname
>     FROM
>       pg_catalog.pg_class c
>       LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
>     WHERE
>       n.nspname like 'pg_temp_%'
>       AND pg_catalog.pg_table_is_visible(c.oid)
>       AND Upper(relname) = 'TEMP_GC'
>     ;

> but as i looked at the system catalogs pg_temp it is like that every session
> can see the temporary tables of any other session. so the whole story about
> the query above is wrong. It checks if ANY session has a temporrary table
> gc_temp and not my own session.

No, not at all: the pg_table_is_visible check will fail on temp tables
of other sessions.

I think the real problem here is a race condition: pg_table_is_visible
will give the "cache lookup failed" error if the OID is for a table that
no longer exists, which means you could have a problem when the select
picks up a pg_class row for another session's temp table just before the
other session drops the temp table.  (The window for this is wider than
it might seem, because pg_table_is_visible operates under SnapshotNow
rules instead of MVCC.)  We've gone back and forth about whether it'd be
better for pg_table_is_visible to silently return FALSE if the OID is
not a valid table OID, but that doesn't seem real attractive from an
error-detection perspective.

In any case I don't think this has anything to do with your original
report about a duplicate key error.  If you can reproduce that one
again, let us know.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: getting the ranks out of items with SHARED
Next
From: Russ Brown
Date:
Subject: Re: Quotation marks in queries