Pg upgrade bug with NOT NULL NOT VALID

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Pg upgrade bug with NOT NULL NOT VALID
Date: 2026-05-21 12:14:07
Message-ID: CALdSSPgYCJu2AjUti9gnW9n7jfE-xZBDLA=n7N3JOQYCfUd+=g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On pg 17:

create table t(i int not null);
alter table t add constraint t_i_not_null check((i is not null)) not valid;

then upgrade to current master, will fail with

```
pg_restore: error: could not execute query: ERROR: constraint
"t_i_not_null" for relation "t" already exists
Command was: ALTER TABLE "public"."t"
ADD CONSTRAINT "t_i_not_null" CHECK (("i" IS NOT NULL)) NOT VALID;
```

I think we need to fix this in the spirit of [0]. I'm currently
thinking of choosing a less obvious name for NOT NULL constraint that
is created during CREATE TABLE processing. Is that a good way to
address this? This will impact non-pg_upgrade creations too, is this
important?

If so, I will share a patch on this

[0] https://git.postgresql.org/cgit/postgresql.git/commit/?id=3db61db48ef5b8898f7e85f98548fdec79d76524

--
Best regards,
Kirill Reshke

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-05-21 12:29:35 Re: Fix pg_stat_wal_receiver to show CONNECTING status
Previous Message Michael Paquier 2026-05-21 12:08:54 Re: Fix pg_stat_wal_receiver to show CONNECTING status