Re: In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”? - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”?
Date
Msg-id 20180721063655.ykzx2poj3l53verg@alvherre.pgsql
Whole thread Raw
In response to In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”?  (Praveen Kumar <pk1uuu@gmail.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: hamann.w@t-online.de
Date:
Subject: Re: sql questions
Next
From: Didier Carlier
Date:
Subject: Finding out why parallel queries not avoided