Re: [PATCH] Fix pg_dump --clean with inherited partition constraints

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: lin teletele <teletele(dot)lin(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH] Fix pg_dump --clean with inherited partition constraints
Date: 2026-10-10 07:03:40
Message-ID: CACJufxE8H7wYdrwasNfn4LpGYpX2XT-xODRWA+OiOkqPcm45-Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Oct 10, 2026 at 10:20 AM lin teletele <teletele(dot)lin(at)gmail(dot)com> wrote:
>
> Hi,
>
> I found that pg_restore --clean still reports errors when restoring a
> partitioned table with a PRIMARY KEY or UNIQUE constraint.
>
> While testing this change, I also found a related failure involving a
> local constraint whose backing index is attached to a partitioned index
> without a corresponding parent constraint. In that case, dropping the
> parent index fails because of the child constraint's dependency. This
> failure also occurs without the proposed patch.
>
> I plan to report that case in a separate thread, where we can discuss
> its cleanup behavior and a follow-up fix.
>

Since these issues all involve pg_dump and constraints, maybe one thread
is enough for all of them.

For example, while looking at your thread, I found another bug related
to pg_dump --clean and constraints.
----------------------
drop table if exists p1, p1_c1;
create table p1(f1 int constraint inh_check_constraint check (f1 > 0)
not enforced);
create table p1_c1(f1 int);
alter table p1_c1 add constraint inh_check_constraint check (f1 > 0) not valid;
alter table p1_c1 inherit p1;

pg_dump --table-and-children=p1 --no-owner --no-acl --clean
--if-exists --no-data
will produce:
-------------------------
ALTER TABLE IF EXISTS public.p1_c1 DROP CONSTRAINT IF EXISTS
inh_check_constraint;
ALTER TABLE IF EXISTS public.p1 DROP CONSTRAINT IF EXISTS inh_check_constraint;
DROP TABLE IF EXISTS public.p1_c1;
DROP TABLE IF EXISTS public.p1;
-------------------------
ALTER TABLE IF EXISTS public.p1_c1 DROP CONSTRAINT IF EXISTS
inh_check_constraint;
would error out if we run it again on an existing cluster.

--
jian
https://www.enterprisedb.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Manu 2026-10-10 07:02:22 O(N^3) planning time in choose_plan_name() since 8c49a484e8e