pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: 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: Fri, 31 Aug 2012 15:14:05 -0400
Message-ID: <1346439762-sup-9541@alvh.no-ip.org> (raw)
In-Reply-To: <1346430351-sup-5026@alvh.no-ip.org>
References: <E1SiEL6-0002u2-Ov@wrigleys.postgresql.org>
	<26225.1340419030@sss.pgh.pa.us>
	<1346425015-sup-3266@alvh.no-ip.org>
	<29703.1346429879@sss.pgh.pa.us>
	<1346430351-sup-5026@alvh.no-ip.org>

Excerpts from Alvaro Herrera's message of vie ago 31 12:26:50 -0400 2012:
> Excerpts from Tom Lane's message of vie ago 31 12:17:59 -0400 2012:
> > Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > > Aha, I see the bug.  It seems the split for AlterObjectNamespace_oid
> > > related to tables was done at the wrong level: there should be a new
> > > AlterTableNamespace_internal call that does all the extra stuff, and
> > > which is to be called from AlterObjectNamespace_oid.
> > 
> > Sounds reasonable to me.  Are you going to fix it, or should I?  If
> > it was introduced in the extensions patch then it's my fault ...
> 
> I'm looking into it.

Here's a patch.  Note I'm not attempting to create a regression test
because that seems to involve setting up a fake extension which I don't
know how to do (would be too messy, I think).  So I tested it by having
isn--1.0.sql create a table with a primary key: create the extension,
alter it to move to a new schema, drop the original schema (public).  If
I then try to dump the database, pg_dump in current HEAD fails with "no
schema with OID 2200" (not verbatim; OID is for the old public schema).
It seems to me that this is exactly what was reported initially.  Also I
verified that psql's \d reports the inconsistency of the table and its
PK.

Patched code works fine.

For some reason, AlterSeqNamespaces was being passed a schema name.
This wasn't used and was not possible to keep in the patched code so I
just removed it.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

alter-extension-schema.patch (application/octet-stream, 5.3K) download *** a/src/backend/commands/alter.c --- b/src/backend/commands/alter.c *************** *** 261,280 **** AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid) case OCLASS_CLASS: { Relation rel; - Relation classRel; rel = relation_open(objid, AccessExclusiveLock); oldNspOid = RelationGetNamespace(rel); ! classRel = heap_open(RelationRelationId, RowExclusiveLock); ! ! AlterRelationNamespaceInternal(classRel, ! objid, ! oldNspOid, ! nspOid, ! true); ! ! heap_close(classRel, RowExclusiveLock); relation_close(rel, NoLock); break; --- 261,271 ---- case OCLASS_CLASS: { Relation rel; rel = relation_open(objid, AccessExclusiveLock); oldNspOid = RelationGetNamespace(rel); ! AlterTableNamespaceInternal(rel, oldNspOid, nspOid); relation_close(rel, NoLock); break; *** a/src/backend/commands/tablecmds.c --- b/src/backend/commands/tablecmds.c *************** *** 263,270 **** 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); static void ATExecValidateConstraint(Relation rel, char *constrName, bool recurse, bool recursing, LOCKMODE lockmode); static int transformColumnNameList(Oid relId, List *colList, --- 263,269 ---- static void AlterIndexNamespaces(Relation classRel, Relation rel, Oid oldNspOid, Oid newNspOid); static void AlterSeqNamespaces(Relation classRel, Relation rel, ! Oid oldNspOid, Oid newNspOid, LOCKMODE lockmode); static void ATExecValidateConstraint(Relation rel, char *constrName, bool recurse, bool recursing, LOCKMODE lockmode); static int transformColumnNameList(Oid relId, List *colList, *************** *** 9710,9716 **** AlterTableNamespace(AlterObjectSchemaStmt *stmt) Oid relid; Oid oldNspOid; Oid nspOid; - Relation classRel; RangeVar *newrv; relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock, --- 9709,9714 ---- *************** *** 9752,9761 **** AlterTableNamespace(AlterObjectSchemaStmt *stmt) /* common checks on switching namespaces */ CheckSetNamespace(oldNspOid, nspOid, RelationRelationId, relid); /* 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); --- 9750,9771 ---- /* common checks on switching namespaces */ CheckSetNamespace(oldNspOid, nspOid, RelationRelationId, relid); + AlterTableNamespaceInternal(rel, oldNspOid, nspOid); + + /* close rel, but keep lock until commit */ + relation_close(rel, NoLock); + } + + void + AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid) + { + Relation classRel; + /* OK, modify the pg_class row and pg_depend entry */ classRel = heap_open(RelationRelationId, RowExclusiveLock); ! AlterRelationNamespaceInternal(classRel, RelationGetRelid(rel), 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); } /* --- 9774,9786 ---- if (rel->rd_rel->relkind == RELKIND_RELATION) { AlterIndexNamespaces(classRel, rel, oldNspOid, nspOid); ! AlterSeqNamespaces(classRel, rel, oldNspOid, nspOid, AccessExclusiveLock); ! AlterConstraintNamespaces(RelationGetRelid(rel), oldNspOid, nspOid, ! false); } heap_close(classRel, RowExclusiveLock); } /* *************** *** 9861,9867 **** AlterIndexNamespaces(Relation classRel, Relation rel, */ static void AlterSeqNamespaces(Relation classRel, Relation rel, ! Oid oldNspOid, Oid newNspOid, const char *newNspName, LOCKMODE lockmode) { Relation depRel; SysScanDesc scan; --- 9869,9875 ---- */ static void AlterSeqNamespaces(Relation classRel, Relation rel, ! Oid oldNspOid, Oid newNspOid, LOCKMODE lockmode) { Relation depRel; SysScanDesc scan; *** a/src/include/commands/tablecmds.h --- b/src/include/commands/tablecmds.h *************** *** 36,41 **** extern void AlterTableInternal(Oid relid, List *cmds, bool recurse); --- 36,44 ---- extern void AlterTableNamespace(AlterObjectSchemaStmt *stmt); + extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, + Oid nspOid); + extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry);

view thread (28+ messages)  latest in thread

Message-ID: <1346439762-sup-9541@alvh.no-ip.org>
Permalink:  ../1346439762-sup-9541@alvh.no-ip.org/
Also on:    postgresql.org/message-id/1346439762-sup-9541@alvh.no-ip.org

 ·  · 

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: alvherre@2ndquadrant.com, tgl@sss.pgh.pa.us, jeff@pgexperts.com
  Subject: Re: BUG #6704: ALTER EXTENSION postgis SET SCHEMA leaves dangling relations
  In-Reply-To: <1346439762-sup-9541@alvh.no-ip.org>
  References: <E1SiEL6-0002u2-Ov@wrigleys.postgresql.org> <26225.1340419030@sss.pgh.pa.us> <1346425015-sup-3266@alvh.no-ip.org> <29703.1346429879@sss.pgh.pa.us> <1346430351-sup-5026@alvh.no-ip.org> <1346439762-sup-9541@alvh.no-ip.org>

* 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