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 1m97jr-00015y-02 for pgsql-docs@arkaria.postgresql.org; Thu, 29 Jul 2021 15:14:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m97jp-0004jf-UK for pgsql-docs@arkaria.postgresql.org; Thu, 29 Jul 2021 15:14:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m97jp-0004jX-OR for pgsql-docs@lists.postgresql.org; Thu, 29 Jul 2021 15:14:21 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m97jn-0004jc-8c for pgsql-docs@lists.postgresql.org; Thu, 29 Jul 2021 15:14:21 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1m97jl-0003kq-RA; Thu, 29 Jul 2021 11:14:17 -0400 Date: Thu, 29 Jul 2021 11:14:17 -0400 From: Bruce Momjian To: anthony@berglas.org, pgsql-docs@lists.postgresql.org Subject: Re: Common case not at all clear Message-ID: <20210729151417.GH9600@momjian.us> References: <162744408450.25751.18322473171054919168@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <162744408450.25751.18322473171054919168@wrigleys.postgresql.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 28, 2021 at 03:48:04AM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/13/transaction-iso.html > Description: > > For all this documentation, it is completely unclear how to handle the most > common, simple case. I.e. > > Select balance into :bal ...where key =123; > Update set balance = :bal+100 where key = 100 > > The discussion of read committed for Updates is misleading, I am pretty sure > it will fail if the select is in a different statement, a common case. > > For Oracle, I think that by default a Select will return values at the > beginning of a transaction, Select For Update will return the read committed > value, and Select For Update will wait until conflicting transactions > complete. So the answer is that the first Select would be a Select For > Update, which should be the normal pattern to be safe (with primary key > access) and minimize deadlocks. > > Is that how PostgreSql works? Is that the generally recommended pattern? > Impossible to tell from the docs as written. MVCC really relies on Select > For Update to work for transactions, I think. What documentation text is unclear? -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com If only the physical world exists, free will is an illusion.