From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: pk1u.uu@gmail.com
Cc: pgsql-general@lists.postgresql.org
Subject: Re: In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”?
Date: Sat, 21 Jul 2018 02:36:55 -0400
Message-ID: <20180721063655.ykzx2poj3l53verg@alvherre.pgsql> (raw)
In-Reply-To: <CAKmKwddyuSpCQ5ek828EgtEBi-Te3d2zHe3soRy5tLPbw=XoQQ@mail.gmail.com>
On 2018-Jul-20, Praveen Kumar wrote:
> Regarding UPDATEs on rows that are locked via "SELECT FOR UPDATE" in
> another transaction, I read the above as follows: other transactions that
> attempt UPDATE of these rows will be blocked until the current transaction
> ( which did "SELECT FOR UPDATE" for those rows ) ends, unless the columns
> in these rows being UPDATE'ed are those that don't have a unique index on
> them that can be used in a foreign key.
>
> Is this correct ?
No. What it means that if you UPDATE the columns-indexed-by-unique-idx
then the FOR UPDATE lock is acquired underneath. If your UPDATE
modifies some other column, then a FOR NO KEY UPDATE lock is acquired
instead. In both cases, concurrent transactions would be blocked rather
than erroring out.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
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-general@postgresql.org
Cc: alvherre@2ndquadrant.com, pk1u.uu@gmail.com
Subject: Re: In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”?
In-Reply-To: <20180721063655.ykzx2poj3l53verg@alvherre.pgsql>
References: <CAKmKwddyuSpCQ5ek828EgtEBi-Te3d2zHe3soRy5tLPbw=XoQQ@mail.gmail.com> <20180721063655.ykzx2poj3l53verg@alvherre.pgsql>
* 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