Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oKZgP-0003di-7v for pgsql-general@arkaria.postgresql.org; Sun, 07 Aug 2022 06:22:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oKZgO-0005ZH-5R for pgsql-general@arkaria.postgresql.org; Sun, 07 Aug 2022 06:22:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oKZgN-0005Z8-RV for pgsql-general@lists.postgresql.org; Sun, 07 Aug 2022 06:22:39 +0000 Received: from securemail-y54.synaq.com ([196.35.198.57]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oKZgL-00039h-1u for pgsql-general@lists.postgresql.org; Sun, 07 Aug 2022 06:22:38 +0000 Authentication-Results: synaq.com; iprev=fail smtp.remote-ip=197.90.32.26; auth=pass (PLAIN) smtp.auth=frank@chagford.com; arc=none Received: from [197.90.32.26] (helo=[192.168.0.8]) by securemail-pl-omx7.synaq.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oKZfj-000N50-Gq for pgsql-general@lists.postgresql.org; Sun, 07 Aug 2022 08:22:29 +0200 Message-ID: <080a1a96-a4df-fb73-cae9-44c58258b927@chagford.com> Date: Sun, 7 Aug 2022 08:22:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: Question about locking Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <3b981248-1b14-70a1-6366-bc4879dd9e94@chagford.com> From: Frank Millman In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Red-Router: yes X-SYNAQ-Pinpoint-Information: Please contact SYNAQ for more information X-SYNAQ-Pinpoint-ID: 1oKZfj-000N50-Gq X-SYNAQ-Pinpoint: No virus infections found X-SYNAQ-Pinpoint-SpamCheck: not spam, SpamAssassin (not cached, score=-1.811, required 9, autolearn=disabled, ALL_TRUSTED -1.00, DCC_REPUT_00_12 -0.80, NICE_REPLY_A -0.00, T_SCC_BODY_TEXT_LINE -0.01) X-Pinpoint-From: frank@chagford.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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