On Thu, May 11, 2023 at 3:06 PM kyle Hailey <kylelf@gmail.com> wrote:
WHy when I attach a partition , it takes hours to complete (hasn't completed yet) when it should be immediate?
ALTER TABLE jobs ATTACH PARTITION jobs_23_04_05_week
FOR VALUES FROM ('2023-04-05') TO ('2023-04-12');
I created a constraint to make the ATTACH command work immediately
ALTER TABLE jobs_23_04_05_week
ADD CONSTRAINT jobs_23_04_05_week_constraint
CHECK ( enqueue_time IS NOT NULL AND
enqueue_time >= '2023-04-05'::timestamp without time zone AND
enqueue_time < '2023-04-12'::timestamp without time zone ) ;
Column | Type | Collation | Nullable | ----------------------+-----------------------------+-----------+----------+- enqueue_time | timestamp without time zone | | not null |
Do you happen to have a default table with a lot of data in it? That can cause child table attachment to be significantly delayed because it has to compare all the data in the default to see if it matches the new constraint.