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 1s4OPg-003RdP-HO for pgsql-general@arkaria.postgresql.org; Tue, 07 May 2024 17:15:37 +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 1s4OPd-004Bdh-R3 for pgsql-general@arkaria.postgresql.org; Tue, 07 May 2024 17:15:34 +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 1s4OPc-004Bbf-3K for pgsql-general@lists.postgresql.org; Tue, 07 May 2024 17:15:34 +0000 Received: from fout5-smtp.messagingengine.com ([103.168.172.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4OPY-0022B7-OB for pgsql-general@lists.postgresql.org; Tue, 07 May 2024 17:15:32 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 42D2F13808EE; Tue, 7 May 2024 13:15:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 07 May 2024 13:15:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1715102126; x=1715188526; bh=nsh41uqDi0gWNBQd7gmc8ByuqlVwnDZZG7BBtqE+nu8=; b= aNrFoBhXXW395BFZql11+VQ0UnstotHBHTI7UxMC7/t9QEnJ/NrjDEN2axKryUrO bazpfNWG7usZ4xmEz/p31ekIN/hVws7Osv2QV5VCmu+xoJSGzkQxv/dtImDMobxn +VZ8FHW3ZTUUk6CQ+zk16SnMiyf7yijgWcWstRhpvA5AHDS7sXVBuOV0r+jMvelq 2xhQs6WIaMeA8jiIn88RY5pzTOW+TZskH42F4Qc4tphRdTTzPVlmde9KzbeA5cW8 F3z2lIaSMEEsvSR5kaqa3lfbmMPcFAUXL789ns+lbwiqCGP9FMLOTBVBq6SK6mav wuZJAc+ZPp80ml+ex1YroQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715102126; x= 1715188526; bh=nsh41uqDi0gWNBQd7gmc8ByuqlVwnDZZG7BBtqE+nu8=; b=V Sy8lqlavuY0OEWsMNVUidGcto99RPST6T3n19TdVQEnsMuIGAiqsUztvwe7IoPDr M4eUhVyuuA50kL7LSfERIB1mNCqcGSLwpuF45bVV73PsTft6zkd5ITiF7qza98u5 1NROh1CZn69nkUwmkyyEanLcrQ2wp9mrew7WEG/DxvDqCi0LfniwUfZkCYRC3bzs 586FD6TdvPPE5UcSvIv3oy7c519VLEYGxb0MJWiooth5xukKV0ZQqK1QILef/3Lb q4UahsfNzXlHXMpkmpO6YBzVMCDWq1IKqpYhvf+1KyG94hFRZTH3EdDMysQ7jl7e yA51WFJTBiwM8/tXkoESQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvkedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheptegu rhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmqeenucggtffrrghtthgvrhhnpeefgeefieeutdfggfetgefgheekjeehteeileei gfetieekjedvieeviefgheevtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 13:15:24 -0400 (EDT) Message-ID: Date: Tue, 7 May 2024 10:15:23 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Question regarding how databases support atomicity To: Siddharth Jain , Tom Lane Cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" References: <2805642.1714793392@sss.pgh.pa.us> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/7/24 9:48 AM, Siddharth Jain wrote: > Thanks All for the kind responses. I understand how MVCC takes care of > atomicity for updates to rows. I was developing a project where lets say > data for each table is stored in its own folder together with metadata > (we are not talking postgres now). So if I have two tables A and B I > have a folder structure like: > A > \_ metadata.json > B > \_ metadata.json > Now if I want to rename a table, I need to move the folder and also > update metadata accordingly. These are two separate operations but need > to be done atomically - all or none. in this case it is possible that we > succeed in renaming the folder but fail to update metadata for whatever > reason. then if we try to undo the folder rename we get another failure > for whatever reason. how to deal with such scenarios? are there no such > scenarios in postgres? The only thing I can think of is creating a function in one of the untrusted languages plpython3u or plperlu to do the renaming. Then in say plpython3u case wrap the actions in try/except block. On a failure take the appropriate undo action. > > > On Fri, May 3, 2024 at 8:29 PM Tom Lane > wrote: > > "David G. Johnston" > writes: > > On Friday, May 3, 2024, Siddharth Jain > 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 > -- Adrian Klaver adrian.klaver@aklaver.com