Fix lock release for role membership grants in DROP OWNED BY.
authorJeff Davis <jdavis@postgresql.org>
Mon, 3 Aug 2026 19:21:05 +0000 (12:21 -0700)
committerJeff Davis <jdavis@postgresql.org>
Mon, 3 Aug 2026 19:25:31 +0000 (12:25 -0700)
Commit 6566133c5f5 added a case for AuthMemRelationId in
AcquireDeletionLock(), but not ReleaseDeletionLock(). The fall-through
case would go to UnlockDatabaseObject(), which would raise a WARNING;
and the lock would be retained until the end of the transaction.

Add the missing branch.

Discussion: https://postgr.es/m/2487ddcd737d4fc8e408e87aa9ad4365eed3bbb3.camel@j-davis.com
Backpatch-through: 16

src/backend/catalog/dependency.c
src/test/isolation/expected/drop-owned-grant.out [new file with mode: 0644]
src/test/isolation/isolation_schedule
src/test/isolation/specs/drop-owned-grant.spec [new file with mode: 0644]

index 18316a3968bcf88e73d9879f983b75298460ea36..49d7cc1003721662e0ae976ec26b8008d79b898e 100644 (file)
@@ -1529,6 +1529,9 @@ ReleaseDeletionLock(const ObjectAddress *object)
 {
    if (object->classId == RelationRelationId)
        UnlockRelationOid(object->objectId, AccessExclusiveLock);
+   else if (object->classId == AuthMemRelationId)
+       UnlockSharedObject(object->classId, object->objectId, 0,
+                          AccessExclusiveLock);
    else
        /* assume we should lock the whole object not a sub-object */
        UnlockDatabaseObject(object->classId, object->objectId, 0,
diff --git a/src/test/isolation/expected/drop-owned-grant.out b/src/test/isolation/expected/drop-owned-grant.out
new file mode 100644 (file)
index 0000000..ea6cca2
--- /dev/null
@@ -0,0 +1,8 @@
+Parsed test spec with 2 sessions
+
+starting permutation: s1b s1d s2d s1c
+step s1b: BEGIN;
+step s1d: DROP OWNED BY regress_dropowned_grantor;
+step s2d: DROP OWNED BY regress_dropowned_grantor; <waiting ...>
+step s1c: COMMIT;
+step s2d: <... completed>
index 9741b881f02d314e4d2c288785922cd36c5e8cc3..91d3bebcd1ad80a8dbe8f41024f91f5fc4fdd66e 100644 (file)
@@ -119,3 +119,4 @@ test: matview-write-skew
 test: lock-nowait
 test: ddl-dependency-locking
 test: pub-concurrent-drop
+test: drop-owned-grant
diff --git a/src/test/isolation/specs/drop-owned-grant.spec b/src/test/isolation/specs/drop-owned-grant.spec
new file mode 100644 (file)
index 0000000..636cc21
--- /dev/null
@@ -0,0 +1,30 @@
+# Test locking of role membership grants during concurrent DROP OWNED BY.
+
+setup
+{
+   CREATE ROLE regress_dropowned_role;
+   CREATE ROLE regress_dropowned_member;
+   CREATE ROLE regress_dropowned_grantor;
+   GRANT regress_dropowned_role TO regress_dropowned_grantor
+       WITH ADMIN OPTION;
+   SET ROLE regress_dropowned_grantor;
+   GRANT regress_dropowned_role TO regress_dropowned_member;
+   RESET ROLE;
+}
+
+teardown
+{
+   DROP ROLE regress_dropowned_member;
+   DROP ROLE regress_dropowned_grantor;
+   DROP ROLE regress_dropowned_role;
+}
+
+session s1
+step s1b   { BEGIN; }
+step s1d   { DROP OWNED BY regress_dropowned_grantor; }
+step s1c   { COMMIT; }
+
+session s2
+step s2d   { DROP OWNED BY regress_dropowned_grantor; }
+
+permutation s1b s1d s2d s1c