diff options
author | Alvaro Herrera | 2012-10-31 13:52:55 +0000 |
---|---|---|
committer | Alvaro Herrera | 2012-10-31 13:52:55 +0000 |
commit | 04f28bdb8477ad48c7f9987950595764eae3218e (patch) | |
tree | 50a351b9699ce36e50f93f3181460cccaca4d937 /src/backend/commands/extension.c | |
parent | 4af3dda13601d859a20425e3554533fde0549056 (diff) |
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/extension.c')
-rw-r--r-- | src/backend/commands/extension.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index 5aa9bbb19c1..47631beb770 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -2204,6 +2204,7 @@ AlterExtensionNamespace(List *names, const char *newschema) Relation depRel; SysScanDesc depScan; HeapTuple depTup; + ObjectAddresses *objsMoved; if (list_length(names) != 1) ereport(ERROR, @@ -2278,6 +2279,8 @@ AlterExtensionNamespace(List *names, const char *newschema) errmsg("extension \"%s\" does not support SET SCHEMA", NameStr(extForm->extname)))); + objsMoved = new_object_addresses(); + /* * Scan pg_depend to find objects that depend directly on the extension, * and alter each one's schema. @@ -2317,9 +2320,11 @@ AlterExtensionNamespace(List *names, const char *newschema) if (dep.objectSubId != 0) /* should not happen */ elog(ERROR, "extension should not have a sub-object dependency"); + /* Relocate the object */ dep_oldNspOid = AlterObjectNamespace_oid(dep.classId, dep.objectId, - nspOid); + nspOid, + objsMoved); /* * Remember previous namespace of first object that has one |