pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jack Douglas <jack@douglastechnology.co.uk>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13523: Unexplained deadlocks (possible race condition)
Date: Tue, 28 Jul 2015 19:09:25 +0100
Message-ID: <01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk> (raw)
In-Reply-To: <17665.1438105627@sss.pgh.pa.us>
References: <20150728162823.25043.27625@wrigleys.postgresql.org>
	<17665.1438105627@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (8+ messages)  latest in thread

Message-ID: <01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk>
Permalink:  ../01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk/
Also on:    postgresql.org/message-id/01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: jack@douglastechnology.co.uk, tgl@sss.pgh.pa.us
  Subject: Re: BUG #13523: Unexplained deadlocks (possible race condition)
  In-Reply-To: <01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk>
  References: <20150728162823.25043.27625@wrigleys.postgresql.org> <17665.1438105627@sss.pgh.pa.us> <01b001d0c960$894af9e0$9be0eda0$@douglastechnology.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox