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 1kmMGr-00010N-2P for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Dec 2020 19:34:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kmMGp-0007dR-Uz for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Dec 2020 19:34:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmMGp-0007dK-Oz for pgsql-bugs@lists.postgresql.org; Mon, 07 Dec 2020 19:34:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmMGi-0000hu-VW for pgsql-bugs@lists.postgresql.org; Mon, 07 Dec 2020 19:34:03 +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 0B7JXrXc3144851; Mon, 7 Dec 2020 14:33:53 -0500 From: Tom Lane To: Alvaro Herrera cc: pgsql-bugs@lists.postgresql.org Subject: ALTER CONSTRAINT on a partitioned FK isn't working MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3144849.1607369633.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 07 Dec 2020 14:33:53 -0500 Message-ID: <3144850.1607369633@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I reproduced the problem shown in [1]: --- snip --- drop table if exists pt, ref; create table pt(f1 int, f2 int, f3 int, primary key(f1,f2)) partition by list(f1); create table pt1 partition of pt for values in (1); create table pt2 partition of pt for values in (2); create table ref(f1 int, f2 int, f3 int) partition by list(f1); create table ref1 partition of ref for values in (1); create table ref2 partition of ref for values in (2); alter table ref add foreign key(f1,f2) references pt; alter table ref alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values(1,2,3); insert into ref values(1,2,3); delete from pt; -- expected to fail begin; delete from pt; -- this should work, but does not delete from ref; abort; --- snip --- But if you create the FK in one step with alter table ref add foreign key(f1,f2) references pt deferrable initially deferred; then everything behaves as expected. So something is broken about propagating deferred-ness to partition triggers in an ALTER CONSTRAINT. Oddly, it *looks* like it worked if you examine the child tables with "\d+". I surmise that ALTER CONSTRAINT fixes whatever catalog fields psql looks at, but there's some other fields that also need to be updated and aren't being. regards, tom lane [1] https://www.postgresql.org/message-id/flat/75fe0761-a291-86a9-c8d8-490= 6da077469%40gmail.com