From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | pk1u(dot)uu(at)gmail(dot)com |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”? |
Date: | 2018-07-21 06:36:55 |
Message-ID: | 20180721063655.ykzx2poj3l53verg@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Didier Carlier | 2018-07-21 08:15:25 | Finding out why parallel queries not avoided |
Previous Message | hamann.w | 2018-07-21 04:23:07 | Re: sql questions |