pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dimitri Fontaine <dimitri@2ndQuadrant.fr>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: jeff <jeff@pgexperts.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6704: ALTER EXTENSION postgis SET SCHEMA leaves dangling relations
Date: Thu, 13 Sep 2012 18:41:19 +0200
Message-ID: <m2627hvpsg.fsf@2ndQuadrant.fr> (raw)
In-Reply-To: <m2ipbiuele.fsf@2ndQuadrant.fr>
References: <E1SiEL6-0002u2-Ov@wrigleys.postgresql.org>
	<26225.1340419030@sss.pgh.pa.us>
	<20120830214826.GC32350@momjian.us>
	<m2k3vzwouo.fsf@2ndQuadrant.fr>
	<1347454709-sup-1105@alvh.no-ip.org>
	<m2ipbiuele.fsf@2ndQuadrant.fr>

Dimitri Fontaine <dimitri@2ndQuadrant.fr> 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.g...

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support

Attachments:

extsetschema.patch (text/x-patch, 5.5K) download *** 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);

view thread (28+ messages)  latest in thread

Message-ID: <m2627hvpsg.fsf@2ndQuadrant.fr>
Permalink:  ../m2627hvpsg.fsf@2ndQuadrant.fr/
Also on:    postgresql.org/message-id/m2627hvpsg.fsf@2ndQuadrant.fr

 ·  · 

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: dimitri@2ndQuadrant.fr, alvherre@2ndquadrant.com, bruce@momjian.us, tgl@sss.pgh.pa.us, jeff@pgexperts.com
  Subject: Re: BUG #6704: ALTER EXTENSION postgis SET SCHEMA leaves dangling relations
  In-Reply-To: <m2627hvpsg.fsf@2ndQuadrant.fr>
  References: <E1SiEL6-0002u2-Ov@wrigleys.postgresql.org> <26225.1340419030@sss.pgh.pa.us> <20120830214826.GC32350@momjian.us> <m2k3vzwouo.fsf@2ndQuadrant.fr> <1347454709-sup-1105@alvh.no-ip.org> <m2ipbiuele.fsf@2ndQuadrant.fr> <m2627hvpsg.fsf@2ndQuadrant.fr>

* 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