Re: Question regarding how databases support atomicity - Mailing list pgsql-general

From Christophe Pettus
Subject Re: Question regarding how databases support atomicity
Date
Msg-id BA0D2CFA-7BFF-407A-98E8-41FD40B211BD@thebuild.com
Whole thread Raw
In response to Re: Question regarding how databases support atomicity  (Siddharth Jain <siddhsql@gmail.com>)
List pgsql-general

> On May 3, 2024, at 20:02, Siddharth Jain <siddhsql@gmail.com> wrote:
>
>
> The way I understand this is that if there is a failure in-between, we start undoing and reverting the previous
operationsone by one. But what if there is a failure and we are not able to revert an operation. How is that situation
handled?e.g., something failed when we tried to do Step 3. now we revert Step 2 and succeed. but when we try to revert
step1 we fail. what happens now? To me, it seems its impossible to guarantee true atomicity in general. 

PostgreSQL does not "undo" operations as such.  When modifications are made to the database, those modifications
(inserts,updates, deletes) are marked with the ID of the transaction that made them.  A COMMIT or ROLLBACK in
PostgreSQLjust notes if those modifications are now "permanent" (if the transaction committed) or "invisible" (if the
transactionrolled back).  This technique in general is called Multi-Version Concurrency Control.  Here's a good
presentationthat describes how it works in PostgreSQL: 

    https://momjian.us/main/writings/pgsql/mvcc.pdf


pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Question regarding how databases support atomicity
Next
From: Tom Lane
Date:
Subject: Re: Question regarding how databases support atomicity