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

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”?
Дата
Msg-id 20180721063655.ykzx2poj3l53verg@alvherre.pgsql
обсуждение исходный текст
Ответ на In certain cases, can UPDATE transactions fail rather than block waiting for “FOR UPDATE lock”?  (Praveen Kumar <pk1uuu@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: hamann.w@t-online.de
Дата:
Сообщение: Re: sql questions
Следующее
От: Didier Carlier
Дата:
Сообщение: Finding out why parallel queries not avoided