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 01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk
Whole thread Raw
In response to Re: BUG #13523: Unexplained deadlocks (possible race condition)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
> I believe the issue with this is that a SQL function will do parsing (and
maybe planning too; don't feel like checking the code right now) for the
entire function body at once.  This means that due to the INSERT command you
acquire RowExclusiveLock on the "test" table during function body parsing,
before the LOCK command actually executes.  So the LOCK represents a lock
escalation attempt, and deadlocks are to be expected.

That makes perfect sense, many thanks for the explanation.

> This coding technique would be safe in plpgsql, but not in a SQL-language
function.

That's useful to know - I already worked around the issue with a retry-loop
(as I'm basically doing an upsert the 'bad' way with `lock table` - roll on
9.5!)

Kind regards
Jack

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #13523: Unexplained deadlocks (possible race condition)
Next
From: Kevin Grittner
Date:
Subject: Re: BUG #13518: CancelRequest lacks statement identifier