Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd5ddbe

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 fromthe first object scanned in pg_depend when switching its namespacedependency entry to the new one, and use it as a base of comparison forany follow-up checks. It would also be used as the old namespace OID toswitch *from* for the extension's pg_depend entry. Hence, if the firstobject scanned has a namespace different than the one stored in theextension, we would finish by:- Not checking that the extension objects map with the extension'sschema.- Not switching the extension -> namespace dependency entry to the newnamespace provided by the user, making ALTER EXTENSION ineffective.This issue exists since this command has been introduced ind9572c4 forrelocatable extension, so backpatch all the way down to 11. The testcase has been provided by Heikki, that I have tweaked a bit to show theeffects on pg_depend for the extension.Reported-by: Heikki LinnakangasAuthor: Michael Paquier, Heikki LinnakangasDiscussion:https://postgr.es/m/20eea594-a05b-4c31-491b-007b6fceef28@iki.fiBackpatch-through: 11
1 parent3c963d3 commitbd5ddbe

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

‎src/backend/commands/extension.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,7 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
27502750
{
27512751
OidextensionOid;
27522752
OidnspOid;
2753-
OidoldNspOid=InvalidOid;
2753+
OidoldNspOid;
27542754
AclResultaclresult;
27552755
RelationextRel;
27562756
ScanKeyDatakey[2];
@@ -2833,6 +2833,9 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
28332833

28342834
objsMoved=new_object_addresses();
28352835

2836+
/* store the OID of the namespace to-be-changed */
2837+
oldNspOid=extForm->extnamespace;
2838+
28362839
/*
28372840
* Scan pg_depend to find objects that depend directly on the extension,
28382841
* and alter each one's schema.
@@ -2912,12 +2915,6 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
29122915
nspOid,
29132916
objsMoved);
29142917

2915-
/*
2916-
* Remember previous namespace of first object that has one
2917-
*/
2918-
if (oldNspOid==InvalidOid&&dep_oldNspOid!=InvalidOid)
2919-
oldNspOid=dep_oldNspOid;
2920-
29212918
/*
29222919
* If not all the objects had the same old namespace (ignoring any
29232920
* that are not in namespaces), complain.

‎src/test/modules/test_extensions/expected/test_extensions.out

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,49 @@ Objects in extension "test_ext_cine"
312312
table ext_cine_tab3
313313
(9 rows)
314314

315+
--
316+
-- Test extension with objects outside the extension's schema.
317+
--
318+
CREATE SCHEMA test_func_dep1;
319+
CREATE SCHEMA test_func_dep2;
320+
CREATE SCHEMA test_func_dep3;
321+
CREATE EXTENSION test_ext_req_schema1 SCHEMA test_func_dep1;
322+
ALTER FUNCTION test_func_dep1.dep_req1() SET SCHEMA test_func_dep2;
323+
SELECT pg_describe_object(classid, objid, objsubid) as obj,
324+
pg_describe_object(refclassid, refobjid, refobjsubid) as objref,
325+
deptype
326+
FROM pg_depend
327+
WHERE classid = 'pg_extension'::regclass AND
328+
objid = (SELECT oid FROM pg_extension WHERE extname = 'test_ext_req_schema1')
329+
ORDER BY 1, 2;
330+
obj | objref | deptype
331+
--------------------------------+-----------------------+---------
332+
extension test_ext_req_schema1 | schema test_func_dep1 | n
333+
(1 row)
334+
335+
-- fails, as function dep_req1 is not in the same schema as the extension.
336+
ALTER EXTENSION test_ext_req_schema1 SET SCHEMA test_func_dep3;
337+
ERROR: extension "test_ext_req_schema1" does not support SET SCHEMA
338+
DETAIL: function test_func_dep2.dep_req1() is not in the extension's schema "test_func_dep1"
339+
-- Move back the function, and the extension can be moved.
340+
ALTER FUNCTION test_func_dep2.dep_req1() SET SCHEMA test_func_dep1;
341+
ALTER EXTENSION test_ext_req_schema1 SET SCHEMA test_func_dep3;
342+
SELECT pg_describe_object(classid, objid, objsubid) as obj,
343+
pg_describe_object(refclassid, refobjid, refobjsubid) as objref,
344+
deptype
345+
FROM pg_depend
346+
WHERE classid = 'pg_extension'::regclass AND
347+
objid = (SELECT oid FROM pg_extension WHERE extname = 'test_ext_req_schema1')
348+
ORDER BY 1, 2;
349+
obj | objref | deptype
350+
--------------------------------+-----------------------+---------
351+
extension test_ext_req_schema1 | schema test_func_dep3 | n
352+
(1 row)
353+
354+
DROP EXTENSION test_ext_req_schema1 CASCADE;
355+
DROP SCHEMA test_func_dep1;
356+
DROP SCHEMA test_func_dep2;
357+
DROP SCHEMA test_func_dep3;
315358
--
316359
-- Test @extschema:extname@ syntax and no_relocate option
317360
--

‎src/test/modules/test_extensions/sql/test_extensions.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,38 @@ ALTER EXTENSION test_ext_cine UPDATE TO '1.1';
210210

211211
\dx+ test_ext_cine
212212

213+
--
214+
-- Test extension with objects outside the extension's schema.
215+
--
216+
CREATESCHEMAtest_func_dep1;
217+
CREATESCHEMAtest_func_dep2;
218+
CREATESCHEMAtest_func_dep3;
219+
CREATE EXTENSION test_ext_req_schema1 SCHEMA test_func_dep1;
220+
ALTERFUNCTIONtest_func_dep1.dep_req1()SET SCHEMA test_func_dep2;
221+
SELECT pg_describe_object(classid, objid, objsubid)as obj,
222+
pg_describe_object(refclassid, refobjid, refobjsubid)as objref,
223+
deptype
224+
FROM pg_depend
225+
WHERE classid='pg_extension'::regclassAND
226+
objid= (SELECToidFROM pg_extensionWHERE extname='test_ext_req_schema1')
227+
ORDER BY1,2;
228+
-- fails, as function dep_req1 is not in the same schema as the extension.
229+
ALTER EXTENSION test_ext_req_schema1SET SCHEMA test_func_dep3;
230+
-- Move back the function, and the extension can be moved.
231+
ALTERFUNCTIONtest_func_dep2.dep_req1()SET SCHEMA test_func_dep1;
232+
ALTER EXTENSION test_ext_req_schema1SET SCHEMA test_func_dep3;
233+
SELECT pg_describe_object(classid, objid, objsubid)as obj,
234+
pg_describe_object(refclassid, refobjid, refobjsubid)as objref,
235+
deptype
236+
FROM pg_depend
237+
WHERE classid='pg_extension'::regclassAND
238+
objid= (SELECToidFROM pg_extensionWHERE extname='test_ext_req_schema1')
239+
ORDER BY1,2;
240+
DROP EXTENSION test_ext_req_schema1 CASCADE;
241+
DROPSCHEMA test_func_dep1;
242+
DROPSCHEMA test_func_dep2;
243+
DROPSCHEMA test_func_dep3;
244+
213245
--
214246
-- Test @extschema:extname@ syntax and no_relocate option
215247
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp