From b422d04b4d27c58f1a3d3b3a054d2d0ffe2050a9 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Fri, 27 Nov 2026 19:24:06 -0500 Subject: [PATCH v1] pg_dump: Don't mark inherited not-null constraints local in upgrade Binary upgrade prints every not-null constraint anyway, and marking it local skipped the conislocal reset. Reported-by: Atish Prakash <125atishprak@gmail.com> Discussion: https://postgr.es/m/19846-abd715e593eba809@postgresql.org --- src/bin/pg_dump/common.c | 6 ++++-- src/bin/pg_dump/t/002_pg_dump.pl | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index cda9d73a9dd..413d9390559 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -591,9 +591,11 @@ flagInhAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables /* * For versions >18, we must print the not-null constraint locally * for this table even if it isn't really locally defined, but is - * valid for the child and no parent has it as valid. + * valid for the child and no parent has it as valid. Binary + * upgrade is excluded, as it resets conislocal itself. */ - if (fout->remoteVersion >= 180000 && allNotNullsInvalid) + if (fout->remoteVersion >= 180000 && allNotNullsInvalid && + !dopt->binary_upgrade) tbinfo->notnull_islocal[j] = true; /* diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index ec73c4d5be9..5471d7a4cfc 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -1120,6 +1120,17 @@ my %tests = ( }, }, + # binary upgrade must not leave the child's constraint marked local + 'CONSTRAINT NOT NULL / NOT VALID (child1, binary upgrade)' => { + regexp => qr/^ + \QUPDATE pg_catalog.pg_constraint\E\n + \QSET conislocal = false\E\n + \QWHERE contype = 'n' AND conrelid = 'dump_test.test_table_nn_chld1'::pg_catalog.regclass AND\E\n + \Qconname IN ('nn');\E + /xm, + like => { binary_upgrade => 1, }, + }, + 'CONSTRAINT NOT NULL / NO INHERIT' => { create_sql => 'CREATE TABLE dump_test.test_table_nonn ( col1 int NOT NULL NO INHERIT, -- 2.37.1 (Apple Git-137.1)