pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Question about locking
Date: Sun, 7 Aug 2022 00:54:28 -0500
Message-ID: <d8838ea8-cc5f-854a-6e46-6ce2344d64be@gmail.com> (raw)
In-Reply-To: <3b981248-1b14-70a1-6366-bc4879dd9e94@chagford.com>
References: <3b981248-1b14-70a1-6366-bc4879dd9e94@chagford.com>

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.





view thread (3+ messages)  latest in thread

Message-ID: <d8838ea8-cc5f-854a-6e46-6ce2344d64be@gmail.com>
Permalink:  ../d8838ea8-cc5f-854a-6e46-6ce2344d64be@gmail.com/
Also on:    postgresql.org/message-id/d8838ea8-cc5f-854a-6e46-6ce2344d64be@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Question about locking
  In-Reply-To: <d8838ea8-cc5f-854a-6e46-6ce2344d64be@gmail.com>
  References: <3b981248-1b14-70a1-6366-bc4879dd9e94@chagford.com> <d8838ea8-cc5f-854a-6e46-6ce2344d64be@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox