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

From Tom Lane
Subject Re: Question regarding how databases support atomicity
Date
Msg-id 2805642.1714793392@sss.pgh.pa.us
Whole thread Raw
In response to Re: Question regarding how databases support atomicity  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: Question regarding how databases support atomicity
List pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Friday, May 3, 2024, 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 operations one by one.

> Not in PostgreSQL.  All work performed is considered provisional until a
> commit succeeds.  At which point all provisional work, which had been
> tagged with the same transaction identifier, becomes reality to the rest of
> the system, by virtue of marking the transaction live.

Right.  We don't use UNDO; instead, we use multiple versions of
database rows (MVCC).  A transaction doesn't modify the contents
of existing rows, but just marks them as provisionally outdated, and
then inserts new row versions that are marked provisionally inserted.
Other transactions ignore the outdate markings and the uncommitted new
rows, until the transaction commits, at which time the new versions
become live and the old ones become dead.  If the transaction never
does commit -- either through ROLLBACK or a crash -- then the old row
versions remain live and the new ones are dead.  In either case, we
don't have a consistency or correctness problem, but we do have dead
rows that must eventually get vacuumed away to prevent indefinite
storage bloat.  That can be done by background housekeeping processes
though (a/k/a autovacuum).

I believe Oracle, for one, actually does use UNDO.  I don't know
what they do about failure-to-UNDO.

            regards, tom lane



pgsql-general by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: Question regarding how databases support atomicity
Next
From: jian he
Date:
Subject: Re: \dt shows table but \d says the table doesn't exist ?