pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Bug with temporary child of a permanent table after recovery
Date: Fri, 14 Dec 2012 12:43:53 -0500
Message-ID: <2959.1355507033@sss.pgh.pa.us> (raw)
In-Reply-To: <50CB1455.3080002@vmware.com>
References: <50CB1455.3080002@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Heikki Linnakangas <hlinnakangas@vmware.com> writes:
> Spotted by accident while working on a patch:
> Open psql and do:

> CREATE TABLE uctest(f1 int, f2 text);
> -- Create a temporary child of the permanent table
> CREATE TEMP TABLE ucchild () inherits (uctest);

> In another terminal:
> pg_ctl stop -m immediate
> pg_ctl start

> psql (9.3devel)
> Type "help" for help.

> postgres=# SELECT * FROM uctest;
> ERROR:  could not open file "base/12030/t2_16392": No such file or directory

> This goes back to 9.1.

I believe this used to work before Robert redesigned temp relations.
The underlying physical file got removed during postmaster restart, but
at this point the catalog entry for the temp table is still there, and
the planner is failing to disregard it as intended.  The problem is that
the RELATION_IS_OTHER_TEMP macro

#define RELATION_IS_OTHER_TEMP(relation) \
	((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP \
	&& (relation)->rd_backend != MyBackendId)

is getting fooled by a chance collision of backend IDs --- that is,
the failure only occurs in sessions with the same BackendId that the
original table creator had.

It worked before because the "is my temp table" test was based on
whether the table belonged to myTempNamespace, which would be InvalidOid
until the backend had started using the temp namespace --- and one of
the things involved in that is to run around and clean out any leftover
tables in that schema.

I'm not sure where rd_backend gets set up, but maybe we can fix this
by not allowing rd_backend to acquire a valid value unless we've begun
using the temp namespace.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (8+ messages)  latest in thread

Message-ID: <2959.1355507033@sss.pgh.pa.us>
Permalink:  ../2959.1355507033@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2959.1355507033@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, hlinnakangas@vmware.com, robertmhaas@gmail.com
  Subject: Re: Bug with temporary child of a permanent table after recovery
  In-Reply-To: <2959.1355507033@sss.pgh.pa.us>
  References: <50CB1455.3080002@vmware.com> <2959.1355507033@sss.pgh.pa.us>

* 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