I think that the transaction tutorial document (3.4) should mention transaction isolation

From: PG Doc comments form <noreply(at)postgresql(dot)org>
To: pgsql-docs(at)lists(dot)postgresql(dot)org
Cc: noamraph(at)gmail(dot)com
Subject: I think that the transaction tutorial document (3.4) should mention transaction isolation
Date: 2023-03-02 13:55:31
Message-ID: 167776533152.987840.17852197823152196095@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/15/tutorial-transactions.html
Description:

Hi,

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.

Thanks,
Noam

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2023-03-10 15:30:25 Make SSPI documentation clearer
Previous Message David G. Johnston 2023-03-01 16:45:00 Re: Mistake in statement example