Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 871dd02

Browse files
committed
Disallow deletion of CurrentExtensionObject while running extension script.
While the deletion in itself wouldn't break things, any further creation of objects in the script would result in dangling pg_depend entries being added by recordDependencyOnCurrentExtension(). An example from Phil Sorber convinced me that this is just barely likely enough to be worth expending a couple lines of code to defend against. The resulting error message might be confusing, but it's better than leaving corrupted catalog contents for the user to deal with.
1 parent 269755e commit 871dd02

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/backend/commands/extension.c

+17
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,23 @@ RemoveExtensionById(Oid extId)
15771577
HeapTuple tuple;
15781578
ScanKeyData entry[1];
15791579

1580+
/*
1581+
* Disallow deletion of any extension that's currently open for insertion;
1582+
* else subsequent executions of recordDependencyOnCurrentExtension()
1583+
* could create dangling pg_depend records that refer to a no-longer-valid
1584+
* pg_extension OID. This is needed not so much because we think people
1585+
* might write "DROP EXTENSION foo" in foo's own script files, as because
1586+
* errors in dependency management in extension script files could give
1587+
* rise to cases where an extension is dropped as a result of recursing
1588+
* from some contained object. Because of that, we must test for the case
1589+
* here, not at some higher level of the DROP EXTENSION command.
1590+
*/
1591+
if (extId == CurrentExtensionObject)
1592+
ereport(ERROR,
1593+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1594+
errmsg("cannot drop extension \"%s\" because it is being modified",
1595+
get_extension_name(extId))));
1596+
15801597
rel = heap_open(ExtensionRelationId, RowExclusiveLock);
15811598

15821599
ScanKeyInit(&entry[0],

0 commit comments

Comments
 (0)