Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 7D939119C295 for ; Thu, 8 Mar 2012 15:44:40 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S5jGO-0001Ui-UP for pgsql-bugs@postgresql.org; Thu, 08 Mar 2012 19:44:39 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q28JiLXq000926; Thu, 8 Mar 2012 14:44:21 -0500 (EST) To: Dimitri Fontaine cc: Phil Sorber , pgsql-bugs@postgresql.org Subject: Re: Extension tracking temp table and causing update failure In-reply-to: <13187.1331227161@sss.pgh.pa.us> References: <21101.1331071837@sss.pgh.pa.us> <87linc93iq.fsf@hi-media-techno.com> <8167.1331135949@sss.pgh.pa.us> <15629.1331145998@sss.pgh.pa.us> <13187.1331227161@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 08 Mar 2012 12:19:21 -0500" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <738.1331235381.0@sss.pgh.pa.us> Date: Thu, 08 Mar 2012 14:44:21 -0500 Message-ID: <925.1331235861@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/69 X-Sequence-Number: 32630 ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <738.1331235381.1@sss.pgh.pa.us> I wrote: > Dimitri Fontaine writes: >> Could we force temp tables created in an extension script to be ON >> COMMIT DROP so that CurrentExtensionObject is still set and your patch >> kicks in, preventing the DROP cascading? > Huh, yeah, that might work. It's ugly but at least the ugliness is > localized; and there's no obvious reason why such a temp table ought to > survive past the end of the script. Actually, after I got done hacking the temp-schema case, I realized that preventing temp tables from becoming extension members isn't so ugly as I first thought; in fact, it's pretty much a one-liner, and much cleaner than hacking ON COMMIT DROP. PFA a patch that fixes both of the temp-table issues. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-patch; charset="us-ascii" Content-ID: <738.1331235381.2@sss.pgh.pa.us> Content-Description: no-temp-in-extensions.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index a8653cd49562d95748c8fe38517aa1d0785c9aff..d1d458d7fa485606f1c0e877fd= d558b42f6ea273 100644 *** a/src/backend/catalog/heap.c --- b/src/backend/catalog/heap.c *************** AddNewRelationType(const char *typeName, *** 957,966 **** --- 957,968 ---- * reltablespace: OID of tablespace it goes in * relid: OID to assign to new rel, or InvalidOid to select a new OID * reltypeid: OID to assign to rel's rowtype, or InvalidOid to select on= e + * reloftypeid: if a typed table, OID of underlying type; else InvalidOi= d * ownerid: OID of new rel's owner * tupdesc: tuple descriptor (source of column definitions) * cooked_constraints: list of precooked check constraints and defaults * relkind: relkind for new rel + * relpersistence: rel's persistence status (permanent, temp, or unlogge= d) * shared_relation: TRUE if it's to be a shared relation * mapped_relation: TRUE if the relation will use the relfilenode map * oidislocal: TRUE if oid column (if any) should be marked attislocal *************** heap_create_with_catalog(const char *rel *** 1235,1240 **** --- 1237,1246 ---- * should they have any ACL entries. The same applies for extension * dependencies. * + * If it's a temp table, we do not make it an extension member; this + * prevents the unintuitive result that deletion of the temp table at + * session end would make the whole extension go away. + * * Also, skip this in bootstrap mode, since we don't make dependencies * while bootstrapping. */ *************** heap_create_with_catalog(const char *rel *** 1255,1261 **** = recordDependencyOnOwner(RelationRelationId, relid, ownerid); = ! recordDependencyOnCurrentExtension(&myself, false); = if (reloftypeid) { --- 1261,1268 ---- = recordDependencyOnOwner(RelationRelationId, relid, ownerid); = ! if (relpersistence !=3D RELPERSISTENCE_TEMP) ! recordDependencyOnCurrentExtension(&myself, false); = if (reloftypeid) { diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespa= ce.c index 80d6fc7d0c2c721b43751cfe0d1d7233796f7d31..dc8f8eaf3f3f60f51fd8b59aa7= 8ccfc36e1b23f9 100644 *** a/src/backend/catalog/namespace.c --- b/src/backend/catalog/namespace.c *************** InitTempTableNamespace(void) *** 3558,3564 **** * temp tables. This works because the places that access the temp * namespace for my own backend skip permissions checks on it. */ ! namespaceId =3D NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID); /* Advance command counter to make namespace visible */ CommandCounterIncrement(); } --- 3558,3565 ---- * temp tables. This works because the places that access the temp * namespace for my own backend skip permissions checks on it. */ ! namespaceId =3D NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID, ! true); /* Advance command counter to make namespace visible */ CommandCounterIncrement(); } *************** InitTempTableNamespace(void) *** 3582,3588 **** toastspaceId =3D get_namespace_oid(namespaceName, true); if (!OidIsValid(toastspaceId)) { ! toastspaceId =3D NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID)= ; /* Advance command counter to make namespace visible */ CommandCounterIncrement(); } --- 3583,3590 ---- toastspaceId =3D get_namespace_oid(namespaceName, true); if (!OidIsValid(toastspaceId)) { ! toastspaceId =3D NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID, ! true); /* Advance command counter to make namespace visible */ CommandCounterIncrement(); } diff --git a/src/backend/catalog/pg_namespace.c b/src/backend/catalog/pg_n= amespace.c index d5ab48a59dc76eb1eff7e6ad4229e87693ba00c2..be812a246c09dbc92f762fb50f= 1a6fac0e074f73 100644 *** a/src/backend/catalog/pg_namespace.c --- b/src/backend/catalog/pg_namespace.c *************** *** 26,35 **** = /* ---------------- * NamespaceCreate * --------------- */ Oid ! NamespaceCreate(const char *nspName, Oid ownerId) { Relation nspdesc; HeapTuple tup; --- 26,43 ---- = /* ---------------- * NamespaceCreate + * + * Create a namespace (schema) with the given name and owner OID. + * + * If isTemp is true, this schema is a per-backend schema for holding + * temporary tables. Currently, the only effect of that is to prevent i= t + * from being linked as a member of any active extension. (If someone + * does CREATE TEMP TABLE in an extension script, we don't want the temp + * schema to become part of the extension.) * --------------- */ Oid ! NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp) { Relation nspdesc; HeapTuple tup; *************** NamespaceCreate(const char *nspName, Oid *** 82,89 **** /* dependency on owner */ recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId); = ! /* dependency on extension */ ! recordDependencyOnCurrentExtension(&myself, false); = /* Post creation hook for new schema */ InvokeObjectAccessHook(OAT_POST_CREATE, NamespaceRelationId, nspoid, 0)= ; --- 90,98 ---- /* dependency on owner */ recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId); = ! /* dependency on extension ... but not for magic temp schemas */ ! if (!isTemp) ! recordDependencyOnCurrentExtension(&myself, false); = /* Post creation hook for new schema */ InvokeObjectAccessHook(OAT_POST_CREATE, NamespaceRelationId, nspoid, 0)= ; diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/sche= macmds.c index 916328529a071d94b668f7b789a15cb179e631e4..6745af501d4680ad08d5945cb2= 89a1af3716afb3 100644 *** a/src/backend/commands/schemacmds.c --- b/src/backend/commands/schemacmds.c *************** CreateSchemaCommand(CreateSchemaStmt *st *** 94,100 **** save_sec_context | SECURITY_LOCAL_USERID_CHANGE); = /* Create the schema's namespace */ ! namespaceId =3D NamespaceCreate(schemaName, owner_uid); = /* Advance cmd counter to make the namespace visible */ CommandCounterIncrement(); --- 94,100 ---- save_sec_context | SECURITY_LOCAL_USERID_CHANGE); = /* Create the schema's namespace */ ! namespaceId =3D NamespaceCreate(schemaName, owner_uid, false); = /* Advance cmd counter to make the namespace visible */ CommandCounterIncrement(); diff --git a/src/include/catalog/pg_namespace.h b/src/include/catalog/pg_n= amespace.h index aad76a1452aae126c468553bec752182a980ff12..1daba477b409a453bfbe19885f= d57455c56245cc 100644 *** a/src/include/catalog/pg_namespace.h --- b/src/include/catalog/pg_namespace.h *************** DESCR("standard public schema"); *** 79,84 **** /* * prototypes for functions in pg_namespace.c */ ! extern Oid NamespaceCreate(const char *nspName, Oid ownerId); = #endif /* PG_NAMESPACE_H */ --- 79,84 ---- /* * prototypes for functions in pg_namespace.c */ ! extern Oid NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp= ); = #endif /* PG_NAMESPACE_H */ ------- =_aaaaaaaaaa0--