diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-10-31 10:49:14 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-10-31 10:49:14 -0300 |
commit | 65225900de86044948c70e9732d02d99412eb171 (patch) | |
tree | 760f8713336ef222807b81533a92033019407e72 /src/backend/commands/alter.c | |
parent | ff8f7103b559d8f19731157aca38650a938fedef (diff) | |
download | postgresql-65225900de86044948c70e9732d02d99412eb171.tar.gz postgresql-65225900de86044948c70e9732d02d99412eb171.zip |
Fix ALTER EXTENSION / SET SCHEMA
In its original conception, it was leaving some objects into the old
schema, but without their proper pg_depend entries; this meant that the
old schema could be dropped, causing future pg_dump calls to fail on the
affected database. This was originally reported by Jeff Frost as #6704;
there have been other complaints elsewhere that can probably be traced
to this bug.
To fix, be more consistent about altering a table's subsidiary objects
along the table itself; this requires some restructuring in how tables
are relocated when altering an extension -- hence the new
AlterTableNamespaceInternal routine which encapsulates it for both the
ALTER TABLE and the ALTER EXTENSION cases.
There was another bug lurking here, which was unmasked after fixing the
previous one: certain objects would be reached twice via the dependency
graph, and the second attempt to move them would cause the entire
operation to fail. Per discussion, it seems the best fix for this is to
do more careful tracking of objects already moved: we now maintain a
list of moved objects, to avoid attempting to do it twice for the same
object.
Authors: Alvaro Herrera, Dimitri Fontaine
Reviewed by Tom Lane
Diffstat (limited to 'src/backend/commands/alter.c')
-rw-r--r-- | src/backend/commands/alter.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index d02bf7fba5d..0f4e0f701ab 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -270,7 +270,8 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) * object doesn't have a schema. */ Oid -AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid) +AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, + ObjectAddresses *objsMoved) { Oid oldNspOid = InvalidOid; ObjectAddress dep; @@ -284,20 +285,11 @@ 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); + AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved); relation_close(rel, NoLock); break; @@ -308,7 +300,7 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid) break; case OCLASS_TYPE: - oldNspOid = AlterTypeNamespace_oid(objid, nspOid); + oldNspOid = AlterTypeNamespace_oid(objid, nspOid, objsMoved); break; case OCLASS_COLLATION: |