Question about locking

Started by Frank Millmanover 3 years ago3 messagesgeneral
Jump to latest
#1Frank Millman
frank@chagford.com

Hi all

Apologies if this is an FAQ, but I could not find the answer I was
looking for.

I want to run two SELECTs, one immediately after the other.

I want to ensure that no other process updates the database in between
the two.

What is the best way to achieve this?

Thanks

Frank Millman

#2Ron
ronljohnsonjr@gmail.com
In reply to: Frank Millman (#1)
Re: Question about locking

On 8/7/22 00:30, Frank Millman wrote:

Hi all

Apologies if this is an FAQ, but I could not find the answer I was looking
for.

I want to run two SELECTs, one immediately after the other.

I want to ensure that no other process updates the database in between the
two.

What is the best way to achieve this?

You probably want to put the queries in a Repeatable Read transaction, or
even a READ ONLY serialized transaction.
https://www.postgresql.org/docs/12/transaction-iso.html#XACT-REPEATABLE-READ
https://www.postgresql.org/docs/12/transaction-iso.html#XACT-SERIALIZABLE
https://www.postgresql.org/docs/12/sql-set-transaction.html

--
Angular momentum makes the world go 'round.

#3Frank Millman
frank@chagford.com
In reply to: Ron (#2)
Re: Question about locking

On 2022-08-07 7:54 AM, Ron wrote:

On 8/7/22 00:30, Frank Millman wrote:

Hi all

Apologies if this is an FAQ, but I could not find the answer I was
looking for.

I want to run two SELECTs, one immediately after the other.

I want to ensure that no other process updates the database in
between the two.

What is the best way to achieve this?

You probably want to put the queries in a Repeatable Read transaction,
or even a READ ONLY serialized transaction.
https://www.postgresql.org/docs/12/transaction-iso.html#XACT-REPEATABLE-READ

https://www.postgresql.org/docs/12/transaction-iso.html#XACT-SERIALIZABLE
https://www.postgresql.org/docs/12/sql-set-transaction.html

Thanks, Ron. That is exactly what I am looking for.

Frank