Re: Question regarding how databases support atomicity

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Siddharth Jain <siddhsql(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Question regarding how databases support atomicity
Date: 2024-05-04 03:20:49
Message-ID: BA0D2CFA-7BFF-407A-98E8-41FD40B211BD@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On May 3, 2024, at 20:02, Siddharth Jain <siddhsql(at)gmail(dot)com> wrote:
>
>
> The way I understand this is that if there is a failure in-between, we start undoing and reverting the previous operations one 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 step 1 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 PostgreSQL just notes if those modifications are now "permanent" (if the transaction committed) or "invisible" (if the transaction rolled back). This technique in general is called Multi-Version Concurrency Control. Here's a good presentation that describes how it works in PostgreSQL:

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-05-04 03:29:52 Re: Question regarding how databases support atomicity
Previous Message David G. Johnston 2024-05-04 03:13:16 Re: Question regarding how databases support atomicity