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 1romuq-003MOR-VI for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2024 16:11:17 +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 1romup-005bNN-I5 for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2024 16:11:16 +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 1romup-005bKh-9o for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2024 16:11:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1romuk-006MQ5-5s for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2024 16:11:14 +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 42PGB9Xw2497245; Mon, 25 Mar 2024 12:11:09 -0400 From: Tom Lane To: scott_ribe@elevated-dev.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18405: flaw in dump of inherited/dropped constraints In-reply-to: <18405-4ce10e802e8d3174@postgresql.org> References: <18405-4ce10e802e8d3174@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 23 Mar 2024 18:09:02 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2497243.1711383069.1@sss.pgh.pa.us> Date: Mon, 25 Mar 2024 12:11:09 -0400 Message-ID: <2497244.1711383069@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Create the following schema: > create table t1 (c boolean not null); > create table t2 (c boolean) inherits (t1); > alter table t2 alter c drop not null; > ... > The drop of the not null constraint is not reflected in the dump. Thus > playing back the dump results in column c of table t2 having the not null > constraint. I'm not super excited about doing anything about that in the back branches. It's fundamentally bogus that we allowed the DROP NOT NULL in the first place, because this structure allows a SELECT from t1 to see null values of c, which is pretty inconsistent. As of HEAD, we don't allow it any more: regression=# create table t1 (c boolean not null); CREATE TABLE regression=# create table t2 (c boolean) inherits (t1); NOTICE: merging column "c" with inherited definition CREATE TABLE regression=# alter table t2 alter c drop not null; ERROR: cannot drop inherited constraint "t1_c_not_null" of relation "t2" thanks to Alvaro's work to treat NOT NULL the same way we've long treated more general CHECK constraints. So there's no need to do anything in v17, and I think changing the behavior in released branches would draw more complaints than plaudits. (Also, if pg_dump did try harder to duplicate this situation, the result would likely be that the dump would fail to load into v17+.) > ... So it looks like prior to 16, plain dumps had this > problem, but custom format dumps did not. Given the way pg_dump works, that's pretty hard to believe: you should get bitwise the same result from pg_dump to text versus pg_dump -Fc | pg_restore. Can you provide a self-contained test showing a case where it doesn't? > One more thing, making the custom format dump using pg_dump 14, then > restoring with pg_restore 16, gets the erroneous not null > constraint. Hmmm ... maybe using a different pg_restore version would affect this. But mostly pg_restore just emits what it finds in the dump file, unless you told it to filter things. I tried dumping a situation like this in a v14 database using various pg_dump and pg_restore versions, and they all produced the same table definitions. regards, tom lane