BUG #19847: pg_dump loses ENFORCED on inherited CHECK under NOT ENFORCED parent

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: 125atishprak(at)gmail(dot)com
Subject: BUG #19847: pg_dump loses ENFORCED on inherited CHECK under NOT ENFORCED parent
Date: 2026-11-07 15:12:50
Message-ID: 19847-f91f92380ce652c9@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19847
Logged by: Atish Prakash
Email address: 125atishprak(at)gmail(dot)com
PostgreSQL version: 19rc1
Operating system: Linux x86_64
Description:

If a child's inherited CHECK constraint is made ENFORCED while the parent's
stays
NOT ENFORCED, a dump and restore silently makes the child's constraint NOT
ENFORCED. The restored table then accepts rows the original rejects, with no
warning from pg_dump or from the restore.

CREATE TABLE ckp(a int, CONSTRAINT c CHECK (a > 0) NOT ENFORCED);
CREATE TABLE ckc() INHERITS (ckp);
ALTER TABLE ckc ALTER CONSTRAINT c ENFORCED;

INSERT INTO ckc VALUES (-1);
-- ERROR: new row for relation "ckc" violates check constraint "c"

Then run pg_dump and restore into an empty database:

INSERT INTO ckc VALUES (-1);
-- INSERT 0 1

pg_constraint for ckc.c:

original: conenforced = t, convalidated = t, conislocal = f,
coninhcount = 1
restored: conenforced = f, convalidated = f, conislocal = f,
coninhcount = 1

Expected: the restored child constraint stays ENFORCED.

The dump contains only the parent's constraint, which the child inherits
when it
is created, so nothing records the child's different state. A child that has
its
own local constraint is not affected: an ENFORCED partition attached under a
NOT
ENFORCED parent restored correctly in my test.

pg_upgrade from 19rc1 to master kept ENFORCED in my test, so this affects
plain
dumps.

Probably the same mechanism: a child's constraint that was validated while
the
parent's stays NOT VALID comes back NOT VALID after a restore:

CREATE TABLE c8p(a int);
CREATE TABLE c8c(a int) INHERITS (c8p);
ALTER TABLE c8p ADD CONSTRAINT k CHECK (a > 0) NOT VALID;
ALTER TABLE c8c VALIDATE CONSTRAINT k;

I have not written a patch.

Found with dump and restore differential tests. I reproduced and checked the
result myself.

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-11-07 15:15:42 BUG #19848: BEGIN ATOMIC with unnamed/OUT params breaks restore and pg_upgrade
Previous Message PG Bug reporting form 2026-11-07 15:10:48 BUG #19846: dump/restore marks inherited NOT VALID not-null constraint as local