Re: BUG #13523: Unexplained deadlocks (possible race condition)

From: "Jack Douglas" <jack(at)douglastechnology(dot)co(dot)uk>
To: "'Andres Freund'" <andres(at)anarazel(dot)de>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13523: Unexplained deadlocks (possible race condition)
Date: 2015-07-30 08:57:11
Message-ID: 01b001d0caa5$b8ea93e0$2abfbba0$@douglastechnology.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Maxim Boguk 2015-07-30 11:48:12 Re: BUG #13528: LATERAL vs. correlated scalar subquery
Previous Message Jack Douglas 2015-07-30 08:56:45 Re: BUG #13523: Unexplained deadlocks (possible race condition)