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: exclusion(at)gmail(dot)com
Cc: alvherre(at)kurilemu(dot)de, 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-28 15:09:17
Message-ID: CAPHduZDsQCpnxRsvj8W3eO7=D22ZjdYKQ-mE02+PBU=x-nyx0Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 27.11.2026, Alexander Lakhin wrote:
> I've found another case, which probably should be fixed as well:
> create table inh_nn1 (f1 int primary key references inh_nn1);
> alter table inh_nn1 alter constraint inh_nn1_f1_not_null no inherit;
> ...
> pg_restore: error: could not execute query: ERROR: cannot create primary
key on column "f1"

Thanks. This one isn't about inheritance or the foreign key, and it
isn't specific to pg_upgrade. A plain table is enough:

create table t (f1 int primary key);
alter table t alter constraint t_f1_not_null no inherit;

and then a plain pg_dump of it fails to restore with the same error,
on master and on 18.7.

CREATE TABLE and ADD PRIMARY KEY both reject a NO INHERIT not-null
constraint on a primary key column (verifyNotNullPKCompatible), but
ALTER CONSTRAINT ... NO INHERIT doesn't check for a primary key, so it
can create a state that the dump can't reproduce. I think the fix
belongs there rather than in pg_dump. The attached patch rejects it
with the error that DROP NOT NULL already reports for a primary key
column:

ERROR: column "f1" is in a primary key

and adds that statement to the existing negative tests in inherit.sql,
which use the same table as your report. The test fails without the
change. With it, the regress, pg_upgrade and pg_dump suites pass on
master, and the regress suite passes on REL_18_STABLE. The patch
applies to REL_19_STABLE and REL_18_STABLE as is.

This doesn't help a v18 cluster that already has such a table: it
still won't dump or upgrade until the constraint is made inheritable
again with ALTER CONSTRAINT ... INHERIT. Should pg_upgrade's check
report it, or is the error message (which has that hint) enough?

Regards,
Sai Pranav

Attachment Content-Type Size
v1-0001-Disallow-making-a-primary-key-column-s-not-null-c.patch text/x-patch 3.8 KB

Browse pgsql-bugs by date

  From Date Subject
Next Message Pierre Forstmann 2026-11-28 15:20:27 Re: BUG #19891: pg_restore ignores an explicitly empty -F argument
Previous Message Raja Sai pranav 2026-11-28 15:09:15 Re: btree_gist: <-> fails on same-sign infinite intervals