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 1s35nP-009JXG-FY for pgsql-general@arkaria.postgresql.org; Sat, 04 May 2024 03:10:43 +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 1s35nM-00ELg8-L1 for pgsql-general@arkaria.postgresql.org; Sat, 04 May 2024 03:10:41 +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 1s35nM-00ELg0-9x for pgsql-general@lists.postgresql.org; Sat, 04 May 2024 03:10:41 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s35nG-001RIF-LQ for pgsql-general@lists.postgresql.org; Sat, 04 May 2024 03:10:40 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6ee2fb4ec57so163775a34.3 for ; Fri, 03 May 2024 20:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714792232; x=1715397032; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DS6cDzI0os7e7VcxgnCdVjlwhy+jgp8t/6K6y0XeLPU=; b=l/vplfX3sTVVOBDlRUsAiAzHfYhKROb/ndgvq6rvXc101hUaJLI8Bq58lFCXNNcM6J 9jKyzzi30vKfAfSULIvTD0Lr5VvVbNUhGnFLUAURvVnVDPIdH000WmGaQfr3JZNYdKgR OGZW0peyxTK666QtcbLNqe5g7WxUV/EM/q/Fpgq2fmhr996dSIWhJt1fJ0lHWBcr7TOo sjk13uTqPqzAT/g3DCRedZnhFrwNMcu4TBdnpWRMY2eajTk6YNCqkgfslyraK0O8aqI/ P+T1w2Sr4L6P9AmnD7DXYU40oSj8Del/ILUZQdWaaaFs7M9k17ajWGi0ENO91ytIGQJo 23Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714792232; x=1715397032; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DS6cDzI0os7e7VcxgnCdVjlwhy+jgp8t/6K6y0XeLPU=; b=iojr8kaW1CpF3m9GgUcaqipLzmsQArZwH6RKbLwmTR2wNmxDjbPC9l6fA9X3ewhHPZ qOsrZ/QDJo2lHsGx3CnxxhKykYsgv3BEC4RUYgGaA/tIfhPyBDtEPS5GiHnRI4DKF7lq a1yzh2uSPc0jauaTjeWq3cbrH3PpMT68uVJ085VVe1FtjJJlRti95mAcc9zAkbtISDnQ 6xrOt6ZFnMxXry/YL8K/X3j3ZqLSUzALcwEMGoVPfB2mgAdI7itQUZW9L2cP0CSygX4L sOxM4mM88Y6MikQQnMk5Z4rDPRwaiLUC2vkw3YgH5ogycp5ROarha6XL9sV2Y9VAjb6j KPcg== X-Gm-Message-State: AOJu0YyeJMR7WpmKeIh5V+/gkG7hoZzZND9pbKyKt7VM1TgFPoj7e/u6 oLwLk+m9rYWzPTe5w15Q9xvZFYW0MnCkefm+4/ArKpUEzKsi7byZ47kY/vPMMiOcfydAYGpfsPC WO5F6K+iwbmrRqjfdgJaWRuELMIo= X-Google-Smtp-Source: AGHT+IHLgPD+QsuJ+/ceyj4PZYH08xpa76FJxW5sCYxjF6PjFstrIFFyCPAgC93CQC6VPhNeIWdpTEmiup7y/Acnn70= X-Received: by 2002:a9d:7f02:0:b0:6eb:b266:a2a1 with SMTP id j2-20020a9d7f02000000b006ebb266a2a1mr4298293otq.19.1714792232487; Fri, 03 May 2024 20:10:32 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:5f0a:0:b0:52a:9016:8503 with HTTP; Fri, 3 May 2024 20:10:31 -0700 (PDT) In-Reply-To: References: From: "David G. Johnston" Date: Fri, 3 May 2024 20:10:31 -0700 Message-ID: Subject: Re: Question regarding how databases support atomicity To: Siddharth Jain Cc: "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000e191c70617982d42" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e191c70617982d42 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, May 3, 2024, Siddharth Jain wrote: > > > On Fri, May 3, 2024 at 8:00=E2=80=AFPM Siddharth Jain wrote: > >> I am trying to sharpen my understanding of databases. Let's say there is >> an operation foo as part of the public API that internally translates to >> more than 1 operation - I am sure there are examples like this in postgr= es. >> So to do foo we have to do following in order in all or none fashion: >> >> 1. Step 1 >> 2. Step 2 >> 3. Step 3 >> >> 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. If the commit never happens, either because of error, rollback, or session end, the transaction ends up being left unalive and eventually is cleaned up. You need to ensure a =E2=80=9Cbegin=E2=80=9D happens before Step 1 and a = =E2=80=9Ccommit=E2=80=9D after Step 3. David J. --000000000000e191c70617982d42 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, May 3, 2024, Siddharth Jain <siddhsql@gmail.com> wrote:
<= div dir=3D"ltr">

On Fri, May 3, 2024 at 8:00=E2=80=AFPM Siddharth Jain &= lt;siddhsql@gmail.c= om> wrote:
I am trying to sharpen my understanding of databases. Le= t's say there is an operation foo as part of the public API that intern= ally translates to more than 1 operation - I am sure there are examples lik= e this in postgres. So to do foo we have to do following in order in all or= none fashion:

1. Step 1
2. Step 2
3= . Step 3

The way I understand this is that if ther= e is a failure in-between, we start undoing and reverting the previous oper= ations one by one.

Not in PostgreSQL.=C2=A0 All work performed is considered provisiona= l until a commit succeeds.=C2=A0 At which point all provisional work, which= had been tagged with the same transaction identifier, becomes reality to t= he rest of the system, by virtue of marking the transaction live.=C2=A0 If = the commit never happens, either because of error, rollback, or session end= , the transaction ends up being left unalive and eventually is cleaned up.<= /div>

You need to ensure a =E2=80=9Cbegin=E2=80=9D happe= ns before Step 1 and a =E2=80=9Ccommit=E2=80=9D after Step 3.
David J.

--000000000000e191c70617982d42--