Re: Adding constraints faster

From: sud <suds1434(at)gmail(dot)com>
To: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Adding constraints faster
Date: 2024-05-15 03:02:50
Message-ID: CAD=mzVUjcXY2Ss02aOiNWFCs46902pPM8HbXBrPg0sa=M=osbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 15, 2024 at 2:09 AM Ron Johnson <ronljohnsonjr(at)gmail(dot)com> wrote:

> On Tue, May 14, 2024 at 3:59 PM sud <suds1434(at)gmail(dot)com> wrote:
>
>> *****
>>
> ALTER TABLE ADD FOREIGN KEY ... NOT VALID.
>> ALTER TABLE ... VALIDATE CONSTRAINT;
>>
>>
> This is what we did, back in the PG 12.x period. VALIDATE CONSTRAINT was
> almost instantaneous. (Supporting indices existed, though.)
>
>
Thank you. Actually we do have a composite index on the child table columns
which is referring to the parent table. And in the parent table those
columns are the primary keys. So even then it's taking ~20minutes for each
partition.

So is there some other way to make it run faster
or
Can we run it concurrently
or
Should we keep the existing constraints in "not valid" state only?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kashif Zeeshan 2024-05-15 04:03:55 Re: pg_stat_io clarifications: background worker, writes and reads
Previous Message Alvaro Herrera 2024-05-14 20:45:21 Re: Using ALTER TABLE DETACH PARTITION CONCURRENTLY inside a procedure