From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: dnsl48@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15631: Generated as identity field in a temporary table with on commit drop corrupts system catalogs
Date: Wed, 13 Mar 2019 10:28:11 +0100
Message-ID: <d58c7b32-1ef5-a029-a852-4665d2897780@2ndquadrant.com> (raw)
In-Reply-To: <20190312034630.GH13812@paquier.xyz>
References: <15631-188663b383e1e697@postgresql.org>
<24188.1549917188@sss.pgh.pa.us>
<043b0c10-5a27-b9ff-7451-b8a2ca9327b1@2ndquadrant.com>
<31358.1549981670@sss.pgh.pa.us>
<20190213023817.GD5746@paquier.xyz>
<20190213044104.GE5746@paquier.xyz>
<12a993ea-1ba5-96d7-a0b5-362579fdadc1@2ndquadrant.com>
<20190309013557.GF9266@paquier.xyz>
<e5017903-059f-35f1-6f8e-84401bf90f91@2ndquadrant.com>
<20190312034630.GH13812@paquier.xyz>
On 2019-03-12 04:46, Michael Paquier wrote:
> I can reproduce the issue on a v10 server, for example:
> =# create temporary table foo ( bar int generated by default as identity ) on
> commit drop;
> CREATE TABLE
> =# \q
> $ psql
> =# create temporary table a (b varchar);
> ERROR: XX000: could not open relation with OID 16389
I've been trying to understand why the equivalent case with serial does
not fail even though the code is mostly the same, that is,
create temporary table foo ( bar serial ) on commit drop;
It turns out that there is some funny business going on that has only
been invisible so far.
If you run the above command with serial, the sequence is not temporary
and is not dropped. After the table is dropped (on commit), you still
have stale dependency entries lying around (start from empty instance to
get matching OIDs):
╔═════════╤═══════╤══════════╤════════════╤══════════╤═════════════╤═════════╗
║ classid │ objid │ objsubid │ refclassid │ refobjid │ refobjsubid │
deptype ║
╠═════════╪═══════╪══════════╪════════════╪══════════╪═════════════╪═════════╣
║ 1259 │ 16386 │ 0 │ 2615 │ 16384 │ 0 │ n
║
║ 1259 │ 16386 │ 0 │ 1259 │ 16388 │ 1 │ a
║
╚═════════╧═══════╧══════════╧════════════╧══════════╧═════════════╧═════════╝
(These are sequence -> namespace and sequence -> column.)
You can see that the catalog is faulty at this point by running
select pg_describe_object(refclassid, refobjid, refobjsubid) from pg_depend;
This is all eventually cleaned up because the sequence is in the pg_temp
schema and so will be cleaned up with the schema.
If you run the command with the identity syntax, you get almost the same
stale dependency entries:
╔═════════╤═══════╤══════════╤════════════╤══════════╤═════════════╤═════════╗
║ classid │ objid │ objsubid │ refclassid │ refobjid │ refobjsubid │
deptype ║
╠═════════╪═══════╪══════════╪════════════╪══════════╪═════════════╪═════════╣
║ 1259 │ 16386 │ 0 │ 2615 │ 16384 │ 0 │ n
║
║ 1259 │ 16386 │ 0 │ 1259 │ 16388 │ 1 │ i
║
╚═════════╧═══════╧══════════╧════════════╧══════════╧═════════════╧═════════╝
It's only because of the different deptype that something chokes when it
tries to clean up the temp schema.
Adding a CommandCounterIncrement() somewhere does fix all this. I was
thinking another option for placing this call would be in
ProcessUtilitySlow():
/* Need CCI between commands */
- if (lnext(l) != NULL)
CommandCounterIncrement();
I think we should also make the implicitly created sequence temporary.
Even though the permanent sequence is cleaned up properly, we should
avoid having those sequences write to the WAL.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: peter.eisentraut@2ndquadrant.com, michael@paquier.xyz, tgl@sss.pgh.pa.us, dnsl48@gmail.com
Subject: Re: BUG #15631: Generated as identity field in a temporary table with on commit drop corrupts system catalogs
In-Reply-To: <d58c7b32-1ef5-a029-a852-4665d2897780@2ndquadrant.com>
References: <15631-188663b383e1e697@postgresql.org> <24188.1549917188@sss.pgh.pa.us> <043b0c10-5a27-b9ff-7451-b8a2ca9327b1@2ndquadrant.com> <31358.1549981670@sss.pgh.pa.us> <20190213023817.GD5746@paquier.xyz> <20190213044104.GE5746@paquier.xyz> <12a993ea-1ba5-96d7-a0b5-362579fdadc1@2ndquadrant.com> <20190309013557.GF9266@paquier.xyz> <e5017903-059f-35f1-6f8e-84401bf90f91@2ndquadrant.com> <20190312034630.GH13812@paquier.xyz> <d58c7b32-1ef5-a029-a852-4665d2897780@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox