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 1tiKTD-00EZuK-RH for pgsql-general@arkaria.postgresql.org; Wed, 12 Feb 2025 21:40:36 +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 1tiKTB-00F2hj-LA for pgsql-general@arkaria.postgresql.org; Wed, 12 Feb 2025 21:40: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 1tiKTB-00F2ha-Av for pgsql-general@lists.postgresql.org; Wed, 12 Feb 2025 21:40:34 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tiKT8-000V4h-1N for pgsql-general@lists.postgresql.org; Wed, 12 Feb 2025 21:40:33 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id 8805F11401BC; Wed, 12 Feb 2025 16:40:28 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 12 Feb 2025 16:40:28 -0500 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=1739396428; x=1739482828; bh=FNBnD42Cc5AbnbeS9ZKorgwRJNnfqtJros5RYphkKYk=; b= ZxcoZG4Oc3XITPjepeHtYZBhClOlfThPHnfZTj1ltKrwtWeOgtBuoom8w/aNNpn5 9wnDSzl64nLa0mvpTopUt0y8YLOcXcKS1INpwa4smxbWyJ7zHwAsiqLYZbl6shFI N3oq0nQjX0JIV7p5tZUpbGeqlzP32WRhji4VlESfT7Va7HsUpc4ztx00wIpd17bg UF5cSMSLLDvd0+cJr8BZPLBmJjZCGrCc2Og2Fyd8ozhKKuA8mZppV0qHBg+dalGo MS9FnPziaYgU+8P0m5By0Jb1hYjQC7wHFXmZF3JuUo5mN+keEB2SxaVqcgblrZjF maM4bsK5oaqs24a3C/nUKg== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1739396428; x= 1739482828; bh=FNBnD42Cc5AbnbeS9ZKorgwRJNnfqtJros5RYphkKYk=; b=0 tF0ZmUPuJkXLu5bUjOu6f9xO6H7RBDS5QdOcwQvLjLjWvozGA2AlqQQzC7XPMQMv BJPujUon0DCMqlRErD4p+Q8A/93NRHJA1W2pN/it00ZY7V8w5moPeIA1jMaYYyYN qdYqur4qU9P1QUC4a1k596HbMedW0lhTgAtu7wOiMjlN0mtSAJ7KL0witebrFbM7 tu/PxQAghpWmtSxh1ULpP3JXDfo6VGvBk8CxuKUWVUl9IB9PwdBUk/aMWshG4raI M/j9ID+1eSi8wPwv/kW+/b5nFy5lE3lFIP0wMmpo8yTqKi8eYOGYaryUN/TIANDE hHtm9WA6DzEeSxSAU0duw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeggeellecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddv jeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeefgeefieeutdfggfet gefgheekjeehteeileeigfetieekjedvieeviefgheevtdenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegr khhlrghvvghrrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuth dprhgtphhtthhopehmrghrtggvfhgvrhhnjeesghhmrghilhdrtghomhdprhgtphhtthho pehpghhsqhhlqdhgvghnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Feb 2025 16:40:27 -0500 (EST) Message-ID: <9fa75099-1ee9-43de-ac6e-945841b184eb@aklaver.com> Date: Wed, 12 Feb 2025 13:40:25 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Best Approach for Swapping a Table with its Copy To: Marcelo Fernandes Cc: pgsql-general@lists.postgresql.org References: <8ac6a1dd-db82-4ea7-8186-0c354d79049f@aklaver.com> 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 2/12/25 1:27 PM, Marcelo Fernandes wrote: > On Thu, Feb 13, 2025 at 10:02 AM Adrian Klaver > This is a simplified version of the original table: > > CREATE TABLE bookings ( > id SERIAL PRIMARY KEY, > resource_id INT NOT NULL, > start_date DATE NOT NULL, > end_date DATE NOT NULL > ); > >> 3) The exclusion constraint definition. > > The copy table would have an exclusion constraint such as: > > ALTER TABLE bookings > ADD CONSTRAINT no_date_overlap_for_resource_id > EXCLUDE USING gist ( > resource_id WITH =, > daterange(start_date, end_date, '[]') WITH && > ); Do you know this will not fail on the existing data? > >> 4) Definition of what 'fairly large' is. > > This table is over 400GB Do you have room for a complete copy of the table? > > This is done to avoid having to hold an exclusive lock for a long amount of > time, thus creating application outages. I am not seeing how this can be done without some outage for that table. What sort of time frame is acceptable? > > Hope that clarifies the situation a bit better > - Marcelo -- Adrian Klaver adrian.klaver@aklaver.com