Re: Adding constraints faster - Mailing list pgsql-general

From sud
Subject Re: Adding constraints faster
Date
Msg-id CAD=mzVUjcXY2Ss02aOiNWFCs46902pPM8HbXBrPg0sa=M=osbA@mail.gmail.com
Whole thread Raw
In response to Adding constraints faster  (sud <suds1434@gmail.com>)
List pgsql-general

On Wed, May 15, 2024 at 2:09 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
On Tue, May 14, 2024 at 3:59 PM sud <suds1434@gmail.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?

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Using ALTER TABLE DETACH PARTITION CONCURRENTLY inside a procedure
Next
From: Kashif Zeeshan
Date:
Subject: Re: pg_stat_io clarifications: background worker, writes and reads