HeapTuple tuple;
ScanKeyData entry[1];
+ /*
+ * Disallow deletion of any extension that's currently open for insertion;
+ * else subsequent executions of recordDependencyOnCurrentExtension()
+ * could create dangling pg_depend records that refer to a no-longer-valid
+ * pg_extension OID. This is needed not so much because we think people
+ * might write "DROP EXTENSION foo" in foo's own script files, as because
+ * errors in dependency management in extension script files could give
+ * rise to cases where an extension is dropped as a result of recursing
+ * from some contained object. Because of that, we must test for the case
+ * here, not at some higher level of the DROP EXTENSION command.
+ */
+ if (extId == CurrentExtensionObject)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot drop extension \"%s\" because it is being modified",
+ get_extension_name(extId))));
+
rel = heap_open(ExtensionRelationId, RowExclusiveLock);
ScanKeyInit(&entry[0],