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

Commit4d642b5

Browse files
committed
Disallow extensions from owning the schema they are assigned to.
This situation creates a dependency loop that confuses pg_dump and probablyother things. Moreover, since the mental model is that the extension"contains" schemas it owns, but "is contained in" its extschema (eventhough neither is strictly true), having both true at once is confusing forpeople too. So prevent the situation from being set up.Reported and patched by Thom Brown. Back-patch to 9.1 where extensionswere added.
1 parenta973296 commit4d642b5

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

‎src/backend/commands/extension.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,17 @@ AlterExtensionNamespace(List *names, const char *newschema)
22252225
if (aclresult!=ACLCHECK_OK)
22262226
aclcheck_error(aclresult,ACL_KIND_NAMESPACE,newschema);
22272227

2228+
/*
2229+
* If the schema is currently a member of the extension, disallow moving
2230+
* the extension into the schema. That would create a dependency loop.
2231+
*/
2232+
if (getExtensionOfObject(NamespaceRelationId,nspOid)==extensionOid)
2233+
ereport(ERROR,
2234+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2235+
errmsg("cannot move extension \"%s\" into schema \"%s\" "
2236+
"because the extension contains the schema",
2237+
extensionName,newschema)));
2238+
22282239
/* Locate the pg_extension tuple */
22292240
extRel=heap_open(ExtensionRelationId,RowExclusiveLock);
22302241

@@ -2689,6 +2700,19 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
26892700
getObjectDescription(&object),
26902701
get_extension_name(oldExtension))));
26912702

2703+
/*
2704+
* Prevent a schema from being added to an extension if the schema
2705+
* contains the extension.That would create a dependency loop.
2706+
*/
2707+
if (object.classId==NamespaceRelationId&&
2708+
object.objectId==get_extension_schema(extension.objectId))
2709+
ereport(ERROR,
2710+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2711+
errmsg("cannot add schema \"%s\" to extension \"%s\" "
2712+
"because the schema contains the extension",
2713+
get_namespace_name(object.objectId),
2714+
stmt->extname)));
2715+
26922716
/*
26932717
* OK, add the dependency.
26942718
*/
@@ -2742,8 +2766,8 @@ AlterExtensionOwner_internal(Relation rel, Oid extensionOid, Oid newOwnerId)
27422766
{
27432767
Form_pg_extensionextForm;
27442768
HeapTupletup;
2745-
SysScanDescscandesc;
2746-
ScanKeyDataentry[1];
2769+
SysScanDescscandesc;
2770+
ScanKeyDataentry[1];
27472771

27482772
Assert(RelationGetRelid(rel)==ExtensionRelationId);
27492773

@@ -2811,7 +2835,7 @@ AlterExtensionOwner_oid(Oid extensionOid, Oid newOwnerId)
28112835
Relationrel;
28122836

28132837
rel=heap_open(ExtensionRelationId,RowExclusiveLock);
2814-
2838+
28152839
AlterExtensionOwner_internal(rel,extensionOid,newOwnerId);
28162840

28172841
heap_close(rel,NoLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp