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 1phbtv-00023I-9P for pgsql-docs@arkaria.postgresql.org; Wed, 29 Mar 2023 19:56:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phbtt-0008UF-KG for pgsql-docs@arkaria.postgresql.org; Wed, 29 Mar 2023 19:56:05 +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 1phbtt-0008U6-8P for pgsql-docs@lists.postgresql.org; Wed, 29 Mar 2023 19:56:05 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phbtq-00022v-Bj for pgsql-docs@lists.postgresql.org; Wed, 29 Mar 2023 19:56:04 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1phbto-005HA4-Li; Wed, 29 Mar 2023 15:56:00 -0400 Date: Wed, 29 Mar 2023 15:56:00 -0400 From: Bruce Momjian To: noamraph@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: I think that the transaction tutorial document (3.4) should mention transaction isolation Message-ID: References: <167776533152.987840.17852197823152196095@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <167776533152.987840.17852197823152196095@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 2, 2023 at 01:55:31PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > I just discovered that by default, transactions are not entirely isolated. I > think that the tutorial should mention this. > > The tutorial gives the example of a bank account, where you make two > commands, one to increase the balance and one to decrease the balance, > explaining why you need a transaction. The example, in which the command is > "UPDATE accounts SET balance = balance - 100.00 WHERE name = 'Alice'", would > indeed be correct with the default transaction isolation. However, if the > transaction included getting the balance by a program, adding 100 to it, and > then setting the balance, consistency would not always be kept, since > another transaction could have modified the balance in between. By just > reading the tutorial, the reader would have no idea that this may happen. > > I think that a notice saying that for absolute transaction isolation you > should set the default transaction isolation to serializable, and be > prepared to have transactions fail, and referring to the more details > document, would help users prevent consistency bugs. Well, the point is that the application is _not_ retrieving a value and setting is +100, but rather having the SQL add 100, which is kind of the point. I don't think a tutorial should get into more details than that. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Embrace your flaws. They make you human, rather than perfect, which you will never be.