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.96) (envelope-from ) id 1vx0j0-00A2hQ-3A for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Mar 2026 10:42:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vx0iz-0006qz-0v for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Mar 2026 10:42:05 +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.96) (envelope-from ) id 1vx0iy-0006qg-3B for pgsql-bugs@lists.postgresql.org; Mon, 02 Mar 2026 10:42:05 +0000 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vx0Pi-000000020rE-1lVe for pgsql-bugs@lists.postgresql.org; Mon, 02 Mar 2026 10:22:14 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id CF578EC0389; Mon, 2 Mar 2026 05:22:08 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 02 Mar 2026 05:22:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm2; t=1772446928; x= 1772533328; bh=v0rJGfR0AwWDkLCoi7NqVt6MiF36XhiefOCdGM13usc=; b=Q SDdciFqKMtnMLOi1SfPjpGpbu/FAL5zN6xCee0WpMtNnSouNfe35a48nYKGJHD52 aDqFdRM9zJMhdLouupL1TBproGeq9aNM2hz35r8v1sMRqRP/yo7XYN7z0eMioLys YmqY/TS6an1cIr4V9lpTZ7khjPVtDFAHWbfev1CmsZNEh4o573OtqV20Zh/RunHm rWIacnGHzgVMvSXBzKzHPxRaBTP1I8lKqPdm/VLu4yvE+u07K8P0QtC25XOOmfk0 6a4F4ydFigkNLaLirOPPuWJWDXgDRLB7uMfhPXIDCqMfDyRIJ4/fTIFagAx6swDM UYvv1lCUQySBp0L4k8RvQ== 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:reply-to :subject:subject:to:to:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1772446928; x=1772533328; bh=v0rJGfR0AwWDk LCoi7NqVt6MiF36XhiefOCdGM13usc=; b=UfKS/+1kdHMJ73CBvcrH+9WnkdpDS OOMmna2a+H7Cx2dy1LkUaRjhYiVxgccmgr/Pi2ZaaxN5Ph8rZQsdPWYCylu6X3M2 g6l/5NFivNPXAdQuLaTQ50RyxBJyck8TSfqU3e1jEuNxzadcVMz2BhnuMaTQRrQA aTr0bsuUD7vd+Y6t8AZJRWK+qVaCkPwjPBWHJ72bhdmf0jZPh+z4LTTe+t/tRZkq c3Uf8/CmnKfjLg6UdaRs+eSdDc/kryHK3XHswqTr5lZPdn0B7zIigeYWsjxyC0EK jxewC/o7u1nhOF3yy1DnwPWXuJoxdfmvF/g+fD2gbWAWJTMFGiHEE1i4g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvheejgedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugfgjgesthekredttd dtjeenucfhrhhomheplmhlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehk uhhrihhlvghmuhdruggvqeenucggtffrrghtthgvrhhnpeeiudetgeejueehfffhgeevve dugedtkedtfeeigfekgfeuffetheduveegtedvjeenucffohhmrghinhepphhoshhtghhr vghsqhhlrdhorhhgpdgvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgeskhhurhhi lhgvmhhurdguvgdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtoheprgdrtghhohgukhhofihskhgrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep phhgshhqlhdqsghughhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Mar 2026 05:22:08 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1772446925; bh=V3YWGKNMoXi77ggbgieTzaRAEHm8DcQSKKq8TElFFo4=; h=Date:From:To:Subject:In-Reply-To:From; b=W5aYEQ9KlFWqt3QIjW5jonbPdvfym6VgXqMajpPq/ibZPW+3fOfkO44kNQVHOFsRr bQKtlEODW0QExeuqJ1VnIc2k1D77NtsBxMLZD/OQWjuBpTp56vphsSY/tR5adKQhCD VvNbwcY0k2Clc3dpyWLJspHzGj5qOZeX7/ToXSciqYQxTYJGqDJVyg10Ty77Fzq4xI 5QJoybSVj+pnzzsOs+RpgkGqFvLqsmJ5x55XutXZlHj3P+996F05uOazDPHkj00sJi 19XADY/CXpHq5Ya3mR0jOEOOorqEDt5ZyZngFsblqsETSNKl8Qzh6mDIC3CwOwIIYG LjtoDRm51g4wA== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id 8E4467A; Mon, 02 Mar 2026 11:22:05 +0100 (CET) Date: Mon, 2 Mar 2026 11:22:05 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: a.chodkowska@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19420: Zombie FK exists after partition is detached. Message-ID: <202603021010.lv5ugtfhqxdl@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <19420-ec7f929dce3a7e14@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-Feb-27, PG Bug reporting form wrote: > I have child table with FK defined as folllows > > ALTER TABLE IF EXISTS tst.child_test_1 > ADD CONSTRAINT child_test_1_parent_id_parent_part_by_fkey FOREIGN KEY > (parent_id, parent_part_by) > REFERENCES tst.maintenance_test_1_p20260218 (id, part_by) MATCH SIMPLE > ON UPDATE NO ACTION > ON DELETE CASCADE; > > Somehow postgresql retains the foreign keys of the detached/dropped > partitions, to the parent table partitions. I don't understand this example fully because (unless I misunderstood) it's incomplete. The partition seems to have a foreign key to a partition of a different partitioned table ...? As Laurenz said, we purposely preserve foreign keys on detach. But we had bugs in this area in previous versions, so maybe the problem is simply that you set up the partitions with the old versions, and the FKs have not been updated. See one of those fixes, probably the most relevant one, here: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=53af9491a0439720094a11b72602952d79f59ac7 Version 16.0 already contained this fix, so it certainly shouldn't happen with 16.6; but I don't know what would happen if you were previously running 15.8 or older and then pg_upgrade'd your way to 16. It might be that the upgrade would preserve the broken FKs somehow. we published this query (in the release notes) that should hopefully display FKs that are broken in this way; maybe try that: SELECT conrelid::pg_catalog.regclass AS "constrained table", conname AS constraint, confrelid::pg_catalog.regclass AS "references", pg_catalog.format('ALTER TABLE %s DROP CONSTRAINT %I;', conrelid::pg_catalog.regclass, conname) AS "drop", pg_catalog.format('ALTER TABLE %s ADD CONSTRAINT %I %s;', conrelid::pg_catalog.regclass, conname, pg_catalog.pg_get_constraintdef(oid)) AS "add" FROM pg_catalog.pg_constraint c WHERE contype = 'f' AND conparentid = 0 AND (SELECT count(*) FROM pg_catalog.pg_constraint c2 WHERE c2.conparentid = c.oid) <> ((SELECT count(*) FROM pg_catalog.pg_inherits i WHERE (i.inhparent = c.conrelid OR i.inhparent = c.confrelid) AND EXISTS (SELECT 1 FROM pg_catalog.pg_partitioned_table WHERE partrelid = i.inhparent)) + CASE WHEN pg_catalog.pg_partition_root(conrelid) = confrelid THEN (SELECT count(*) FROM pg_catalog.pg_partition_tree(confrelid) WHERE level = 1) ELSE 0 END); > I try the following methods: > partman.run_maintenance('tst.child_test_1') > partman.run_maintenance() > ALTER TABLE tst.child_test_1 DETACH PARTITION > > The error persisted regardless of the method used. If you can still recreate the problem tables in 16.11, can you provide a standalone reproducer, as a SQL script starting from an empty database? -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "La primera ley de las demostraciones en vivo es: no trate de usar el sistema. Escriba un guión que no toque nada para no causar daños." (Jakob Nielsen)