From 94804a2380d18107040887fa424919eeac97ba90 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Mon, 22 Jul 2024 17:38:06 +0300
Subject: [PATCH 7/8] Release partition lock a little earlier

We don't need to hold the lock to prevent die/cancel interrupts, they
are only processed at explicit CHECK_FOR_INTERRUPTS() points now.
---
 src/backend/storage/lmgr/lock.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 8d1d57c0533..52f2867ffea 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -1043,6 +1043,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
 	{
 		/* No conflict with held or previously requested locks */
 		GrantLock(lock, proclock, lockmode);
+		LWLockRelease(partitionLock);
 	}
 	else
 	{
@@ -1118,8 +1119,10 @@ LockAcquireExtended(const LOCKTAG *locktag,
 				elog(ERROR, "LockAcquire failed");
 			}
 		}
+
 		PROCLOCK_PRINT("LockAcquire: granted", proclock);
 		LOCK_PRINT("LockAcquire: granted", lock, lockmode);
+		LWLockRelease(partitionLock);
 	}
 
 	/* The lock was granted to us.  Update the local lock entry accordingly */
@@ -1131,8 +1134,6 @@ LockAcquireExtended(const LOCKTAG *locktag,
 	 */
 	FinishStrongLockAcquire();
 
-	LWLockRelease(partitionLock);
-
 	/*
 	 * Emit a WAL record if acquisition of this lock needs to be replayed in a
 	 * standby server.
-- 
2.39.2

