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 1oKZFI-0002ce-Nj for pgsql-general@arkaria.postgresql.org; Sun, 07 Aug 2022 05:54:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oKZFG-00080I-IP for pgsql-general@arkaria.postgresql.org; Sun, 07 Aug 2022 05:54:38 +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 1oKZFG-000808-6C for pgsql-general@lists.postgresql.org; Sun, 07 Aug 2022 05:54:38 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oKZF9-0002xZ-KV for pgsql-general@lists.postgresql.org; Sun, 07 Aug 2022 05:54:37 +0000 Received: by mail-oi1-x235.google.com with SMTP id l188so7124054oia.4 for ; Sat, 06 Aug 2022 22:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=ITViwDSZF1CUOCc6VXEtsON3PtDI59Ol/JVpu0mwmpk=; b=VD8c2IxyXyc9l7Pojs/3iyCxhVMsAkkdPAnP9XorPwm4kxZVcNHDh9YVNsn18S6e7r rM5CmrXK1a0rTzPAbHgv2OAz0GNMmQJgnzrYnI4vmEXKjt9oN2St9XYOOvIVuzMnJsnR cYf+o80eM7vz5euk4jSSoziLBbaC9bjbaQOCJPAkgUeVYF59vLs8W8xqBCQ1yIFezTa0 swODwG7AmqtgA67MvlIHxdbQOjkIRzETqL5yI5LEO41FE+ayBJ3sE6KlEjyOaSHn5sHP CsKvUvBUYZpczrHqqRqjK6uCYM8RRTaLkbMaByR1Ugie+PIQC/FzCsrQqHJxdtfuyGQR tlXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=ITViwDSZF1CUOCc6VXEtsON3PtDI59Ol/JVpu0mwmpk=; b=Vwk3+OoMA5U2j2RdmMIEuNG7iqxbHlAPOnxlRSLAyzqRF/hhED8YnjDPleP0yD2Dqo tAEgO2Rc1hX9fGoWO2AApPdpFbK908wHxuFQiWMaBXbxBFzv/6mUU3CTptirn08MeVwK NMjyVw6/6OmgZ4CRB4w6DMoG41lTPsCTjb1H11sY31MKLWtA+zVggfrew6EtECQj3vJv 9BqBV3Ihv88tWpv7JlWenLevKW36z0sSqpy0lROAt1yJqHwjcdfKvERu7+uSmRDAOSVi SS6RPSsZW0Bu9aG70G36swp5BSxer93eiptpYGF++7/q1oAWRGKkb5m2iZmN9HNDQrh4 SPEw== X-Gm-Message-State: ACgBeo16JaXdPzQj0rM9arDi9wFlXII3cd2KLTeNiONOLgyZgXUJHaR7 RC+HpwBmsR6wOKnqip069vT57R3dzUc= X-Google-Smtp-Source: AA6agR7CgvS3u8vhckXWIAm4LfbYYEJ6KK+/n3kT0TIFfnYkMG5wvC0RTIN8FJDTXOuABfYOxzEw8w== X-Received: by 2002:a05:6808:181e:b0:33a:6f26:f011 with SMTP id bh30-20020a056808181e00b0033a6f26f011mr8720084oib.57.1659851669996; Sat, 06 Aug 2022 22:54:29 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id b84-20020aca3457000000b0033b15465357sm1410662oia.5.2022.08.06.22.54.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Aug 2022 22:54:29 -0700 (PDT) Message-ID: Date: Sun, 7 Aug 2022 00:54:28 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Question about locking Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <3b981248-1b14-70a1-6366-bc4879dd9e94@chagford.com> From: Ron In-Reply-To: <3b981248-1b14-70a1-6366-bc4879dd9e94@chagford.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.