Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s35xq-009Npm-9x for pgsql-general@arkaria.postgresql.org; Sat, 04 May 2024 03:21:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s35xn-00EU3S-JQ for pgsql-general@arkaria.postgresql.org; Sat, 04 May 2024 03:21:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s35xn-00EU3K-8P for pgsql-general@lists.postgresql.org; Sat, 04 May 2024 03:21:28 +0000 Received: from smtp97.ord1d.emailsrvr.com ([184.106.54.97]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s35xk-001RUT-8w for pgsql-general@lists.postgresql.org; Sat, 04 May 2024 03:21:27 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp13.relay.ord1d.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 76CF0C0183; Fri, 3 May 2024 23:21:21 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: Re: Question regarding how databases support atomicity From: Christophe Pettus In-Reply-To: Date: Fri, 3 May 2024 20:20:49 -0700 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Siddharth Jain X-Mailer: Apple Mail (2.3774.500.171.1.1) X-Classification-ID: c569a148-93ce-4662-be31-b6c3bae2bde5-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 3, 2024, at 20:02, Siddharth Jain wrote: >=20 >=20 > 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=