From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
Cc: Andrew Sackville-West <awest@janrain.com>
Cc: pgsql-bugs@postgresql.org
Cc: Paulo Tanimoto <paulo@janrain.com>
Subject: Re: regression, deadlock in high frequency single-row UPDATE
Date: Thu, 11 Dec 2014 10:06:53 -0300
Message-ID: <20141211130653.GG1768@alvh.no-ip.org> (raw)
In-Reply-To: <548943C7.2030507@catalyst.net.nz>
References: <20140801005950.GF5475@eldon.alvh.no-ip.org>
<20140804161205.GA30380@andrew-ThinkPad-X230>
<20140804163027.GI5475@eldon.alvh.no-ip.org>
<20141208235552.GZ6930@andrew-ThinkPad-X230>
<54868FA2.80003@catalyst.net.nz>
<CAAdHSJk7E5oNuinLwqTzmqGKRHaMmGa5KwBf9BWAmiNfLyHSgw@mail.gmail.com>
<5487B8F2.6050806@catalyst.net.nz>
<20141210193314.GZ1768@alvh.no-ip.org>
<5488C197.3060900@catalyst.net.nz>
<548943C7.2030507@catalyst.net.nz>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Mark Kirkwood wrote:
> In the most glaringly obvious (and possibly not at all helpful) analysis -
> this is because we are using "FOR KEY SHARE" instead of "FOR SHARE" in the
> newer code. Reverting this (see attached very basic patch) gets rid of the
> deadlock (tested in 9.5devel). However this is obviously a less than
> desirable solution, as it loses any possible concurrency improvement - that
> we worked hard to gain in the patch that added this new lock mode! We really
> want to figure out how to keep "FOR KEY SHARE" and have it *not* deadlock.
Yeah. The problem is that the INSERT in the fktab table takes a FOR KEY
SHARE lock in the pktab table. This puts the inserting process' Xid
into the tuple's Xmax, but allows concurrent UPDATE while the inserter
transaction is still in progress. If you use a FOR SHARE lock, the
UPDATE is disallowed until the inserter transaction is completed.
Having the inserter be live is what causes the heap_lock_tuple and
heap_update calls in the updater process to take the heavyweight tuple
lock.
I think what we should do here is NOT take the HW lock unless we're
going to sleep in heap_lock_tuple and heap_update. Right now we always
take it if HeapTupleSatisfiesUpdate returns HeapTupleBeingUpdated, even
if we end up not sleeping to wait for something else.
I'm going to experiment with that idea and see if it leads to a
solution. I tried the other idea yesterday (to keep the HW tuple lock
we acquire in heap_lock_tuple until heap_update is done) but aside from
being very complicated and bug-prone, it doesn't solve the problem
anyway.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: alvherre@2ndquadrant.com, mark.kirkwood@catalyst.net.nz, awest@janrain.com, paulo@janrain.com
Subject: Re: regression, deadlock in high frequency single-row UPDATE
In-Reply-To: <20141211130653.GG1768@alvh.no-ip.org>
References: <20140801005950.GF5475@eldon.alvh.no-ip.org> <20140804161205.GA30380@andrew-ThinkPad-X230> <20140804163027.GI5475@eldon.alvh.no-ip.org> <20141208235552.GZ6930@andrew-ThinkPad-X230> <54868FA2.80003@catalyst.net.nz> <CAAdHSJk7E5oNuinLwqTzmqGKRHaMmGa5KwBf9BWAmiNfLyHSgw@mail.gmail.com> <5487B8F2.6050806@catalyst.net.nz> <20141210193314.GZ1768@alvh.no-ip.org> <5488C197.3060900@catalyst.net.nz> <548943C7.2030507@catalyst.net.nz> <20141211130653.GG1768@alvh.no-ip.org>
* 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