From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 125atishprak@gmail.com
Subject: BUG #19847: pg_dump loses ENFORCED on inherited CHECK under NOT ENFORCED parent
Date: Sat, 07 Nov 2026 15:12:50 +0000
Message-ID: <19847-f91f92380ce652c9@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19847
Logged by: Atish Prakash
Email address: 125atishprak@gmail.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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, 125atishprak@gmail.com
Subject: Re: BUG #19847: pg_dump loses ENFORCED on inherited CHECK under NOT ENFORCED parent
In-Reply-To: <19847-f91f92380ce652c9@postgresql.org>
References: <19847-f91f92380ce652c9@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox