]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix lock release for role membership grants in DROP OWNED BY. master github/master
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:21:05 +0000 (12:21 -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 c54774b327590e2b3b05aa32c7b88a3439ade216..52cd2caf9d49b8f15b25eb3ce8153fc23677b7ed 100644 (file)
@@ -1600,6 +1600,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 26abed9f9f072b982ead03590c1915b8d79554ec..df8ce44ede654720c8e5223ab2a5c4f91ef5b2fd 100644 (file)
@@ -129,3 +129,4 @@ test: lock-nowait
 test: for-portion-of
 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