8000 Fix ALTER EXTENSION SET SCHEMA with objects outside an extension's sc… · postgres/postgres@914e72e · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 914e72e

Browse files
committed
Fix ALTER EXTENSION SET SCHEMA with objects outside an extension's schema
As coded, the code would use as a base comparison the namespace OID from the first object scanned in pg_depend when switching its namespace dependency entry to the new one, and use it as a base of comparison for any follow-up checks. It would also be used as the old namespace OID to switch *from* for the extension's pg_depend entry. Hence, if the first object scanned has a namespace different than the one stored in the extension, we would finish by: - Not checking that the extension objects map with the extension's schema. - Not switching the extension -> namespace dependency entry to the new namespace provided by the user, making ALTER EXTENSION ineffective. This issue exists since this command has been introduced in d9572c4 for relocatable extension, so backpatch all the way down to 11. The test case has been provided by Heikki, that I have tweaked a bit to show the effects on pg_depend for the extension. Reported-by: Heikki Linnakangas Author: Michael Paquier, Heikki Linnakangas Discussion: https://postgr.es/m/20eea594-a05b-4c31-491b-007b6fceef28@iki.fi Backpatch-through: 11
1 parent 6143602 commit 914e72e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/backend/commands/extension.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
27022702
{
27032703
Oid extensionOid;
27042704
Oid nspOid;
2705-
Oid oldNspOid = InvalidOid D319 ;
2705+
Oid oldNspOid;
27062706
AclResult aclresult;
27072707
Relation extRel;
27082708
ScanKeyData key[2];
@@ -2785,6 +2785,9 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
27852785

27862786
objsMoved = new_object_addresses();
27872787

2788+
/* store the OID of the namespace to-be-changed */
2789+
oldNspOid = extForm->extnamespace;
2790+
27882791
/*
27892792
* Scan pg_depend to find objects that depend directly on the extension,
27902793
* and alter each one's schema.
@@ -2830,12 +2833,6 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
28302833
nspOid,
28312834
objsMoved);
28322835

2833-
/*
2834-
* Remember previous namespace of first object that has one
2835-
*/
2836-
if (oldNspOid == InvalidOid && dep_oldNspOid != InvalidOid)
2837-
oldNspOid = dep_oldNspOid;
2838-
28392836
/*
28402837
* If not all the objects had the same old namespace (ignoring any
28412838
* that are not in namespaces), complain.

0 commit comments

Comments
 (0)
0