Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Z4M-0005a3-2J for pgsql-sql@arkaria.postgresql.org; Wed, 14 Dec 2022 21:13:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5Z4K-0006eK-RZ for pgsql-sql@arkaria.postgresql.org; Wed, 14 Dec 2022 21:13:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Z4K-0006eA-J1 for pgsql-sql@lists.postgresql.org; Wed, 14 Dec 2022 21:13:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Z4I-0000gp-5V for pgsql-sql@lists.postgresql.org; Wed, 14 Dec 2022 21:13:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2BELDWbE2873813; Wed, 14 Dec 2022 16:13:32 -0500 From: Tom Lane To: Steve Midgley cc: Kirmo Uusitalo , Samed YILDIRIM , pgsql-sql@lists.postgresql.org Subject: Re: Postgresql long transaction support In-reply-to: References: Comments: In-reply-to Steve Midgley message dated "Wed, 14 Dec 2022 11:59:44 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2873811.1671052412.1@sss.pgh.pa.us> Date: Wed, 14 Dec 2022 16:13:32 -0500 Message-ID: <2873812.1671052412@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Steve Midgley writes: > This seems pretty complex to address at any layer! But it would be a useful > feature for some situations, for sure. It seems like the approach taken by > Ruby/Rails and similar frameworks for "db migrations" might have some > useful design patterns for you. Each transaction has a link to its future > and past transaction. If the system wants to traverse from "migration 6 to > migration 3" and the DB is currently at migration 6 (stored a version > number in the db itself), it runs the exit function to downgrade to > migration 5, then runs the logic for migration 5, then runs the downgrade > to 4, etc. > It can be slow, as implemented, but it allows you to attach logic to every > step forward and backward in time that ensures you can handle even > structure changes in the tables, etc (as well as changing lookup values in > tables, etc). > Might be worth considering as a design model? If you end up building things that way, PG's "extensions" could be a useful way to package it. What Steve is calling a "migration" corresponds to an extension version, and you can provide scripts to go in either direction between versions. regards, tom lane