Skip to content

Commit 6bd9ae1

Browse files
committed
Lock the extension during ALTER EXTENSION ADD/DROP.
Although we were careful to lock the object being added or dropped, we failed to get any sort of lock on the extension itself. This allowed the ALTER to proceed in parallel with a DROP EXTENSION, which is problematic for a couple of reasons. If both commands succeeded we'd be left with a dangling link in pg_depend, which would cause problems later. Also, if the ALTER failed for some reason, it might try to print the extension's name, and that could result in a crash or (in older branches) a silly error message complaining about extension "(null)". Per bug #17098 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17098-b960f3616c861f83@postgresql.org
1 parent 52c168d commit 6bd9ae1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/backend/commands/extension.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,9 +3196,17 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
31963196
Relation relation;
31973197
Oid oldExtension;
31983198

3199-
extension.classId = ExtensionRelationId;
3200-
extension.objectId = get_extension_oid(stmt->extname, false);
3201-
extension.objectSubId = 0;
3199+
/*
3200+
* Find the extension and acquire a lock on it, to ensure it doesn't get
3201+
* dropped concurrently. A sharable lock seems sufficient: there's no
3202+
* reason not to allow other sorts of manipulations, such as add/drop of
3203+
* other objects, to occur concurrently. Concurrently adding/dropping the
3204+
* *same* object would be bad, but we prevent that by using a non-sharable
3205+
* lock on the individual object, below.
3206+
*/
3207+
extension = get_object_address(OBJECT_EXTENSION,
3208+
(Node *) makeString(stmt->extname),
3209+
&relation, AccessShareLock, false);
32023210

32033211
/* Permission check: must own extension */
32043212
if (!pg_extension_ownercheck(extension.objectId, GetUserId()))

0 commit comments

Comments
 (0)