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

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>, 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-26 09:32:05
Message-ID: 95511e31-1bb3-46f2-8e04-e575e71c0a75@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 22/11/2026 15:45, Raja Sai pranav wrote:
> Hi,
>
> I reproduced this with pg_upgrade from master and an 18.7 old cluster,
> using just the two tables from your script.
>
> check_for_not_null_inheritance() reports a child column that is nullable
> while the parent's column is NOT NULL, but it doesn't look at whether
> the parent's not-null constraint is NO INHERIT. Such a constraint
> doesn't apply to the children, so this is a valid v18 schema.
>
> The attached patch skips parent columns whose not-null constraint
> (contype 'n') is NO INHERIT. Versions before 18 have no not-null
> constraints in pg_constraint, so the check is unchanged for them.
>
> With the patch, pg_upgrade --check passes and the full upgrade works:
> the NULL row is kept, the child column stays nullable, and the parent's
> constraint is still NO INHERIT. A real inconsistency is still reported:
> I made one on 18 by clearing attnotnull on a child column in
> pg_attribute, and the check still lists it.
>
> I didn't add a test, because the check only runs when the old cluster is
> 18 or older, so the same-version pg_upgrade tests never reach it. The
> patch is for master and applies to REL_19_STABLE; REL_18_STABLE doesn't
> have this check.

REL_18_STABLE does have this check too, it runs on a same-version
upgrade. But _why_ do we run that check on a 18->18 upgrade? The
scenario it's checking for should not be possible on a v18 cluster.

There may have been a point in running that check in the v18 development
cycle, for upgrades from older v18devel version to newer v18devel
version. But commit 14e87ffa5c54 landed pretty early in the development
cycle, way before the beta period, so there's no need to support that
anymore.

So I think this needs to be backpatched to REL_18_STABLE too, and the
version guard should be fixed to:

diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 0c150ad4467..ea4b88c35bc 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -675,8 +675,8 @@ check_and_dump_old_cluster(void)
/*
* Pre-PG 18 allowed child tables to omit not-null constraints that their
* parents columns have, but schema restore fails for them. Verify there
* are none, iff applicable.
*/
- if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1800)
+ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1700)
check_for_not_null_inheritance(&old_cluster);

And once you do that, you don't need to change the query in
check_for_not_null_inheritance() anymore, the query is correct for
pre-18 clusters. So all we need to do is fix that version guard.

Am I missing something?

- Heikki

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Raja Sai pranav 2026-11-26 09:53:31 Re: BUG #19928: pg_upgrade fails on v18 schema with NOT NULL ... NO INHERIT and inheritance
Previous Message Daniel Pedersen 2026-11-26 08:11:20 Re: BUG #19939: In a read-only transaction, a plain SELECT ... INTO is refused, but the same statement under EXPLAIN