Hi,
On 2026-04-15 16:50:11 +0200, Antonin Houska wrote:
> I thought of a "hypothetical graph", which would include the to-be-granted
> lock, but the major issue is that it will not work correctly without the
> locking the LMGR's LW locks we do in CheckDeadLock():
>
> for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
> LWLockAcquire(LockHashPartitionLockByIndex(i), LW_EXCLUSIVE);
>
> And obviously, doing this each time we want to insert a lock into the queue
> would be bad for performance.
Hence my suggestion to do this as part of the deadlock check. Then we don't do
this unnecessary work outside of the case where we actually need it.
That does need to deal with the case of the deadlock check running first in
the backend doing repack, but that's not that hard - I think it'd be good
enough to set its deadlock timeout temporarily to a higher value. The backend
*should* still run the deadlock detector, because it could probably still get
into a deadlock (e.g. due to a pg_class access or something).
Greetings,
Andres Freund