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 1tiJuG-00ES36-OH for pgsql-general@arkaria.postgresql.org; Wed, 12 Feb 2025 21:04:28 +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 1tiJuE-00EQ9s-Ov for pgsql-general@arkaria.postgresql.org; Wed, 12 Feb 2025 21:04:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tiJsg-00ELNa-5r for pgsql-general@lists.postgresql.org; Wed, 12 Feb 2025 21:02:51 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tiJse-000SkS-2d for pgsql-general@lists.postgresql.org; Wed, 12 Feb 2025 21:02:49 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id 757DF11400BA; Wed, 12 Feb 2025 16:02:47 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 12 Feb 2025 16:02:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= 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=1739394167; x=1739480567; bh=kXuPu3lNe2yvP7H7izHjI36ewB8Cv7NwZ/kMEIA+LrE=; b= k4GypQtbowjyaqM/Ml7I2QRHgpcq5wCypvXj3NQAM7uolvwlh3xMEdg5P9q33UyG CDgeNXW5O9rPT4bcFCW2gGBdmDR3LMdiGSi61L4MBDrkL//rv/qhWov9UZfeuRqg SzFsvIzvx6zjQWjHwj29wKbld5HlFsiduc1X+hUojDaMtLPibBQXcNpbB3IjRX56 Mqr7CMLoWCDOWPjIIt6vqB1rslNA49xQssuWhrX8+jsAZDuXiIrnLnzgu4qh4qMt G9vN57qpDywHuZFqcgoftwXeeHoKftDaJQ/XaonRCjhWtTFscK1SfdvAB6J4s9Sq oiHzaBjOj+k7jZ6woPaYLw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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-sender :x-me-sender:x-sasl-enc; s=fm3; t=1739394167; x=1739480567; bh=k XuPu3lNe2yvP7H7izHjI36ewB8Cv7NwZ/kMEIA+LrE=; b=e8sSLZPUfQlIYWJcj 7kPwZ4RnNOD5b8e3s9k5N32sSkRjLJct9xK0jBEx+H+IGzSmy+UD3OwjzgU+2VR1 4ibWMgoyNaqv+T+A75F2+GMSb6aMqZXQhG7ZaAdHTptabmUvEfZfMIM5uQ6V8ypi ae6AbTo6baL076OkwyrHGmwH/wNVvL/ktrRpyMDYOTPm/OOVj1T9onGt8gm+ASNQ Pt8ybls7+C08XXAI1UfZMx7ooPs4iDPDjVuObvwmDfuEK522qeWsEUTTMCtQGFo1 Qh5xY+N2sD6H9c9kuuGHC535VpnWpPOZ6F5ft+8UnG2lHELsLDaY1SuvLdfcxlDv 2dtBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeggeeludcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepiedvhfeiheehgeeuieel jeeitedtjeehudegfeelkedvleekhedtgfeiffefkedunecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepmhgrrhgtvghfvghrnhejsehgmhgrihhlrdgtohhmpdhrtghpthhtohep phhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Feb 2025 16:02:46 -0500 (EST) Message-ID: <8ac6a1dd-db82-4ea7-8186-0c354d79049f@aklaver.com> Date: Wed, 12 Feb 2025 13:02:44 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Best Approach for Swapping a Table with its Copy To: Marcelo Fernandes , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/12/25 12:57 PM, Marcelo Fernandes wrote: > Hi folks, > > I have a scenario where I need to swap an original table with a copy of that > table. > > The copy has an exclusion constraint that the original does not have. The main > challenge is to ensure that the swap does not break any existing foreign keys > to the original table and handles the associated TOAST tables correctly. > > Both tables are fairly large and exist in a system where there are no > maintenance time windows where the application is shut down. This needs more information: 1) Postgres version. 2) The table definition. 3) The exclusion constraint definition. 4) Definition of what 'fairly large' is. 5) How is the application interfacing with the database? > > My key questions are: > > - What is the best process for swapping the original table with the copy in > such a way that the foreign key relations are preserved? > > - Are there any special considerations for managing the TOAST tables during > this swap? > > - Should I perform this operation in multiple steps, or is there a > straightforward way to achieve this atomically? > > - Are there any risks of potential issues I should be aware of when doing this > swap? Specifically related to foreign key integrity and TOAST data? > > Thank you! > - Marcelo > > -- Adrian Klaver adrian.klaver@aklaver.com