Re: Queries getting older values (autocommit enabled)

Поиск
Список
Период
Сортировка
От Eudald Valcàrcel Lacasa
Тема Re: Queries getting older values (autocommit enabled)
Дата
Msg-id CANEx+AVGMQs0mO4QnHVZXNSSCeXu8gSxLCJWHXjp2GpK+ERPGw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Queries getting older values (autocommit enabled)  (Eudald Valcàrcel Lacasa <eudald.valcarcel@gmail.com>)
Ответы Re: Queries getting older values (autocommit enabled)  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-bugs
Hello again,
I've been looking for this issue and I'd like to know the behavior of FOR UPDATE SKIP LOCKED in the following scenario:
* One query does an UPDATE targeting a row in the table
* Another query run in parallel does a SELECT...FOR UPDATE SKIP LOCKED targeting the same (being updated) row on the table.
From SKIP LOCKED definition: . With SKIP LOCKED, any selected rows that cannot be immediately locked are skipped.

Would it mean that the 2nd query wouldn't check the affected row since it's locked by the first query?
If that's the behavior, is there any way I could make the SELECT query wait for the UPDATE LOCK? Is it recommended? Are there downsides to this approach?

Thank you,
Eudald

El vie., 24 abr. 2020 a las 18:30, Eudald Valcàrcel Lacasa (<eudald.valcarcel@gmail.com>) escribió:
Hello!
Thanks David and Tom for your answer.
I'll check out mvcc. Would user defined locks on a specific table make PostgreSql underperform too much?

Thanks again,
Eudald

El vie., 24 abr. 2020 a las 18:15, Tom Lane (<tgl@sss.pgh.pa.us>) escribió:
Eudald Valcàrcel Lacasa <eudald.valcarcel@gmail.com> writes:
> Could it be possible that, somehow, the select query starts before the
> update one, although it's printed as if it's being executed after it?

It's certainly possible that the select is using a snapshot that was
taken before the update commits.  You should read this chapter of
the manual for background and some hints:

https://www.postgresql.org/docs/current/mvcc.html

                        regards, tom lane

В списке pgsql-bugs по дате отправления:

Предыдущее
От: PG Bug reporting form
Дата:
Сообщение: BUG #16390: Regression between 12.2 and 11.6 on a recursive query : very slow and overestimation of rows
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Queries getting older values (autocommit enabled)