Re: BUG #19928: pg_upgrade fails on v18 schema with NOT NULL ... NO INHERIT and inheritance

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: alvherre(at)kurilemu(dot)de
Cc: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19928: pg_upgrade fails on v18 schema with NOT NULL ... NO INHERIT and inheritance
Date: 2026-11-30 11:23:40
Message-ID: CAPHduZC47EOd4Wq9FUME-haCj66bfkYQC8e0Q5RLkMSk0yMqPA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2026-Nov-29, Alvaro Herrera wrote:
> Hmm, I didn't verify the code in detail, but I wonder if it would be
> possible to approach this fix better in flagInhAttrs()?

Yes, that works better. v2 attached. flagInhAttrs() already compares each
child column with the same column in the parents, so the dependencies are
now added there, and only between constraints on the same column (v1
linked all of an ancestor's NOT VALID not-null constraints). To reach the
constraint objects from there, getTableAttrs() now records each table's
NOT VALID not-null constraints per column, from conkey.

On master, the pg_upgrade test fails with the reported error without the
pg_dump change, and the regress, pg_dump and pg_upgrade suites pass with
it. I reran plain and pg_restore -j4 restores of the cases from my last
mail, plus a parent with NOT VALID constraints on two columns where the
child has its own on only one of them. Without the patch, four of them
fail in plain or parallel restore; with it, all restore and the catalog
matches the source.

On Alexander's comment case: v2 doesn't fix it, and it's a different
problem. dumpTableConstraintComment() makes the COMMENT entry depend on
the child's constraint, but an inherited NOT VALID not-null constraint
has no TOC entry of its own, so nothing orders the comment after the
parent's ADD CONSTRAINT that creates it. Adding a dependency from the
child's constraint to the parent's fixes a plain restore but not
pg_restore -j4, because the comment entry's dependency is set when it's
created and isn't resolved through the constraint. I'll look at that
separately.

v2 applies to REL_19_STABLE and REL_18_STABLE as is, but I have only
tested it on master so far.

Regards,
Sai Pranav

On Sun, Nov 29, 2026 11:05 PM, Alvaro Herrera <alvherre(at)kurilemu(dot)de> wrote:

> On 2026-Nov-27, Raja Sai pranav wrote:
>
> > Here is a patch. pg_dump now makes each ancestor's NOT VALID not-null
> > constraints depend on the child's own, so the child's command runs first
> > and the parent's then merges into it, the same way the original schema
> > was built. The restored catalog then matches the source: the child keeps
> > its own constraint name, with conislocal = true and coninhcount = 1.
>
> Hmm, I didn't verify the code in detail, but I wonder if it would be
> possible to approach this fix better in flagInhAttrs()?
>
> --
> Álvaro Herrera Breisgau, Deutschland —
> https://www.EnterpriseDB.com/
> "No es bueno caminar con un hombre muerto"
>

Attachment Content-Type Size
v2-0001-pg_dump-Restore-a-child-s-NOT-VALID-not-null-cons.patch text/x-patch 9.6 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Matheus Alcantara 2026-11-30 11:57:34 Re: BUG #19789: "expression not found in statistics object" for a boolean domain column in an MCV statistics object
Previous Message Andrey Rachitskiy 2026-11-30 10:21:42 Re: BUG #19956: json #>, #>> and json_extract_path resolve a negative array index against an earlier sibling array