Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCCTz-000374-KP for pgsql-bugs@postgresql.org; Thu, 13 Sep 2012 16:41:39 +0000 Received: from acidenitrix.villemain.org ([91.121.90.165]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCCTw-0004DX-0H for pgsql-bugs@postgresql.org; Thu, 13 Sep 2012 16:41:38 +0000 Received: from cac94-7-82-243-26-157.fbx.proxad.net ([82.243.26.157] helo=DimIMac.local) by acidenitrix.villemain.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TCCTu-0006ma-8H; Thu, 13 Sep 2012 18:41:34 +0200 From: Dimitri Fontaine To: Alvaro Herrera Cc: Bruce Momjian , Tom Lane , jeff , Pg Bugs Subject: Re: BUG #6704: ALTER EXTENSION postgis SET SCHEMA leaves dangling relations Organization: 2ndQuadrant References: <26225.1340419030@sss.pgh.pa.us> <20120830214826.GC32350@momjian.us> <1347454709-sup-1105@alvh.no-ip.org> User-Mail-Address: dimitri@2ndQuadrant.fr Date: Thu, 13 Sep 2012 18:41:19 +0200 In-Reply-To: (Dimitri Fontaine's message of "Thu, 13 Sep 2012 17:28:29 +0200") Message-ID: User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2 (darwin) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Pg-Spam-Score: -0.3 (/) X-Archive-Number: 201209/118 X-Sequence-Number: 34113 --=-=-= Content-Type: text/plain Dimitri Fontaine writes: > I think we shouldn't change the content of pg_depend lightly here, and So here's a patch following that idea. Even for TIP I don't want us to change how pg_depend tracking is done, because I want to propose a fix for the pg_dump bug wrt sequences and pg_extension_config_dump() wherein you can actually register a sequence (owned by a table or not) but then pg_dump fails to dump it (see report from Marko Kreen) http://archives.postgresql.org/message-id/CACMqXCJjauc9jPa64VxskRN67bYjuYmodz-Mgy-_aoZ6ErG3Yg@mail.gmail.com Regards, -- Dimitri Fontaine http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=extsetschema.patch *** a/src/backend/commands/alter.c --- b/src/backend/commands/alter.c *************** *** 18,23 **** --- 18,24 ---- #include "catalog/dependency.h" #include "catalog/indexing.h" #include "catalog/namespace.h" + #include "catalog/pg_constraint.h" #include "catalog/pg_largeobject.h" #include "catalog/pg_namespace.h" #include "commands/alter.h" *************** *** 268,278 **** AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid) classRel = heap_open(RelationRelationId, RowExclusiveLock); ! AlterRelationNamespaceInternal(classRel, ! objid, ! oldNspOid, ! nspOid, ! true); heap_close(classRel, RowExclusiveLock); --- 269,282 ---- classRel = heap_open(RelationRelationId, RowExclusiveLock); ! AlterRelationNamespace_oid(rel, ! classRel, ! objid, ! oldNspOid, ! nspOid, ! true, ! false, ! NULL); heap_close(classRel, RowExclusiveLock); *** a/src/backend/commands/tablecmds.c --- b/src/backend/commands/tablecmds.c *************** *** 260,267 **** static void StoreCatalogInheritance(Oid relationId, List *supers); static void StoreCatalogInheritance1(Oid relationId, Oid parentOid, int16 seqNumber, Relation inhRelation); static int findAttrByName(const char *attributeName, List *schema); - static void AlterIndexNamespaces(Relation classRel, Relation rel, - Oid oldNspOid, Oid newNspOid); static void AlterSeqNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid, const char *newNspName, LOCKMODE lockmode); --- 260,265 ---- *************** *** 9755,9761 **** AlterTableNamespace(AlterObjectSchemaStmt *stmt) /* OK, modify the pg_class row and pg_depend entry */ classRel = heap_open(RelationRelationId, RowExclusiveLock); ! AlterRelationNamespaceInternal(classRel, relid, oldNspOid, nspOid, true); /* Fix the table's row type too */ AlterTypeNamespaceInternal(rel->rd_rel->reltype, nspOid, false, false); --- 9753,9789 ---- /* OK, modify the pg_class row and pg_depend entry */ classRel = heap_open(RelationRelationId, RowExclusiveLock); ! AlterRelationNamespace_oid(rel, ! classRel, ! relid, ! oldNspOid, ! nspOid, ! true, ! true, ! stmt->newschema); ! ! heap_close(classRel, RowExclusiveLock); ! ! /* close rel, but keep lock until commit */ ! relation_close(rel, NoLock); ! } ! ! /* ! * Relocating a relation to another namespace, and its related objects too. ! * ! * Extensions track both the main table and its owned sequences so it's not ! * necessary to alter the namespace of those sequences when doing ALTER ! * EXTENSION ... SET SCHEMA. alterSeqNamespaces is then false and newschema is ! * NULL. ! */ ! void ! AlterRelationNamespace_oid(Relation rel, Relation classRel, Oid relOid, ! Oid oldNspOid, Oid nspOid, ! bool hasDependEntry, ! bool alterSeqNamespaces, ! char *newschema) ! { ! AlterRelationNamespaceInternal(classRel, relOid, oldNspOid, nspOid, true); /* Fix the table's row type too */ AlterTypeNamespaceInternal(rel->rd_rel->reltype, nspOid, false, false); *************** *** 9764,9778 **** AlterTableNamespace(AlterObjectSchemaStmt *stmt) if (rel->rd_rel->relkind == RELKIND_RELATION) { AlterIndexNamespaces(classRel, rel, oldNspOid, nspOid); - AlterSeqNamespaces(classRel, rel, oldNspOid, nspOid, stmt->newschema, - AccessExclusiveLock); - AlterConstraintNamespaces(relid, oldNspOid, nspOid, false); - } - - heap_close(classRel, RowExclusiveLock); ! /* close rel, but keep lock until commit */ ! relation_close(rel, NoLock); } /* --- 9792,9804 ---- if (rel->rd_rel->relkind == RELKIND_RELATION) { AlterIndexNamespaces(classRel, rel, oldNspOid, nspOid); ! if (alterSeqNamespaces) ! AlterSeqNamespaces(classRel, rel, oldNspOid, nspOid, ! newschema, ! AccessExclusiveLock); ! AlterConstraintNamespaces(relOid, oldNspOid, nspOid, false); ! } } /* *************** *** 9826,9832 **** AlterRelationNamespaceInternal(Relation classRel, Oid relOid, * Note: we assume adequate permission checking was done by the caller, * and that the caller has a suitable lock on the owning relation. */ ! static void AlterIndexNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid) { --- 9852,9858 ---- * Note: we assume adequate permission checking was done by the caller, * and that the caller has a suitable lock on the owning relation. */ ! void AlterIndexNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid) { *** a/src/include/commands/tablecmds.h --- b/src/include/commands/tablecmds.h *************** *** 36,41 **** extern void AlterTableInternal(Oid relid, List *cmds, bool recurse); --- 36,51 ---- extern void AlterTableNamespace(AlterObjectSchemaStmt *stmt); + extern void AlterIndexNamespaces(Relation classRel, Relation rel, + Oid oldNspOid, Oid newNspOid); + + extern void AlterRelationNamespace_oid(Relation rel, + Relation classRel, Oid relOid, + Oid oldNspOid, Oid newNspOid, + bool hasDependEntry, + bool alterSeqNamespaces, + char *newschema); + extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry); --=-=-=--