Re: BUG #13523: Unexplained deadlocks (possible race condition) - Mailing list pgsql-bugs

From Jack Douglas
Subject Re: BUG #13523: Unexplained deadlocks (possible race condition)
Date
Msg-id 01b001d0caa5$b8ea93e0$2abfbba0$@douglastechnology.co.uk
Whole thread Raw
In response to Re: BUG #13523: Unexplained deadlocks (possible race condition)  (Andres Freund <andres@anarazel.de>)
List pgsql-bugs
> I don't think that'd help at all? The problem here is the lock upgrade
from RowExclusiveLock to the exclusive lock, and that'll not be fixed by
that proposal?

The problem is that the RowExclusiveLock is being aquired in one session
before the Exclusive lock, even though the LOCK TABLE statement is
physically first in the SQL function.

Because the locks are being acquired out-of-order, deadlocks become possible
as another session tries to escalate the lock and waits, then the first
session tries to escalate it's own lock and deadlocks.

Normally this is prevented by acquiring the most restrictive lock first, but
with a SQL-language function (unlike plpgsql for example) this is not
possible.

This is how I understand Tom's initial reply, is that not right?

pgsql-bugs by date:

Previous
From: "Jack Douglas"
Date:
Subject: Re: BUG #13523: Unexplained deadlocks (possible race condition)
Next
From: Maxim Boguk
Date:
Subject: Re: BUG #13528: LATERAL vs. correlated scalar subquery