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 1ticZT-000Siv-5x for pgsql-general@arkaria.postgresql.org; Thu, 13 Feb 2025 17:00:15 +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 1ticZR-00Au4d-6G for pgsql-general@arkaria.postgresql.org; Thu, 13 Feb 2025 17:00:13 +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 1ticZQ-00Au4U-Rg for pgsql-general@lists.postgresql.org; Thu, 13 Feb 2025 17:00:13 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ticZP-000e8f-0W for pgsql-general@lists.postgresql.org; Thu, 13 Feb 2025 17:00:13 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 222EC1140226; Thu, 13 Feb 2025 12:00:10 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 13 Feb 2025 12:00:10 -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=1739466010; x=1739552410; bh=JdryRCigCpnCpQY5yJrh06QzP1l7itmoliqvp9ol8lw=; b= clLhWBhxoo/FmhBjGWs9QTaMQQK1FqlTdo11HfqY2U4/txuJUvKUPUKldyvA5z6W JtZ6yR/SofsEchfENFPhf4OTRQo6K2m5Fboh3XCqgI2+Sag1KrZzMjsKK5rL57c9 N+9Ocf5nQZkTmvzHAYSb7Q1PACuRdw6ZFnQqLzFiYNBKo/ohmeQFyR1Fc1k5stkc RGzF7h/O1GniWNjFPeH01NW6G2KpqoRnITxXaYIWGAOvVziPZYdycwi5AJ91+8CM UcIImAmiMS/DQI5dG7AEgfRVEePXnKwtRxuf6Gbx+EqN9Hw/xA/7E/V8FG3509oB Qm4vLn1s9TCmMQwj4b1wng== 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=1739466010; x= 1739552410; bh=JdryRCigCpnCpQY5yJrh06QzP1l7itmoliqvp9ol8lw=; b=B z+EfeKUhd86+rRcE0KIyVjivRoqTxqBKV1tjWTq7OfgxwYWHOHCqfweY5bnmvDqY 1bwNoI+HBgqgaqxK5DHt3x0QmgQRld8ffc0hQktwgOACa/YyAziln8+Ge93nCLtW tdBhmsjOH4KcF0OOCje9I+RFTWFeEzt/8WLVL5lN/08Ql0fanbe5zpeC/OmR0gzz IenPNzXhespBxHbHQQru1v98Le59py7NChwNSYFMIhSfaqVFGbi6AozqQ+vOLFPF z1ayLWJcTXGNIcAe/DqiSFbF3ebGYYPLdqsPQET4tkpvJxKrPePnNOk25YVE6vLX zYOpthMDKrhla8/lkWtnw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegjeefvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddv jeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpefgudefkefhveefleev ieeuveehvdduudekuddvvdelhfeuueeijedtuedvvedvueenucffohhmrghinhepphhosh htghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnh gspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepugguvghv ihgvnhhnvgesghhmrghilhdrtghomhdprhgtphhtthhopehhthgrmhhfihgushesghhmrg hilhdrtghomhdprhgtphhtthhopehmrghrtggvfhgvrhhnjeesghhmrghilhdrtghomhdp rhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvsh hqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Feb 2025 12:00:09 -0500 (EST) Message-ID: <94e1205e-8ddf-403b-8477-02d7939f2905@aklaver.com> Date: Thu, 13 Feb 2025 09:00:07 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Best Approach for Swapping a Table with its Copy To: Dominique Devienne , Greg Sabino Mullane Cc: Marcelo Fernandes , pgsql-general@lists.postgresql.org References: <8ac6a1dd-db82-4ea7-8186-0c354d79049f@aklaver.com> <9fa75099-1ee9-43de-ac6e-945841b184eb@aklaver.com> <22406cdf-83f5-4b98-b07e-7827afe97f93@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/13/25 07:25, Dominique Devienne wrote: > On Thu, Feb 13, 2025 at 4:09 PM Greg Sabino Mullane > wrote: > > > Thanks for the colorful analogy Greg :). > > Maybe the better option is to support ALTER TABLE to ADD an exclusion > constraint, no? That exists: select version(); PostgreSQL 14.15 create table exclusion_test(id integer primary key, dt1 timestamptz, dt2 timestamptz); ALTER TABLE exclusion_test ADD CONSTRAINT dt_overlap EXCLUDE USING gist ( id WITH =, tstzrange(dt1, dt2, '[]') WITH && ); \d exclusion_test Table "public.exclusion_test" Column | Type | Collation | Nullable | Default --------+--------------------------+-----------+----------+--------- id | integer | | not null | dt1 | timestamp with time zone | | | dt2 | timestamp with time zone | | | Indexes: "exclusion_test_pkey" PRIMARY KEY, btree (id) "dt_overlap" EXCLUDE USING gist (id WITH =, tstzrange(dt1, dt2, '[]'::text) WITH &&) > I get that it's not support now. But is it more difficult than the > above? And why then? --DD From here: https://www.postgresql.org/message-id/CAM2F1VOOn1izCrtcrDx4YUtCY-H64Vj5yvN5H1Lhk8kCY%2B_W6Q%40mail.gmail.com " > Why can't you just add the exclusion constraint to the original table? With unique constraints, one can use a unique index to create the constraint concurrently. With check constraints, one can create the constraint as invalid and then validate it while only requiring a share update exclusive lock. But with exclusion constraints, neither of those techniques are available. In that sense, there is no way to create this type of constraint in a large table without copying the original table, adding the constraint, and performing a table swap. This is done to avoid having to hold an exclusive lock for a long amount of time, thus creating application outages. Hope that clarifies the situation a bit better " -- Adrian Klaver adrian.klaver@aklaver.com