add-check-validated
Add CHECK constraints as NOT VALID first.
Severity: error · Lock: ACCESS EXCLUSIVE
Adding a CHECK constraint scans the whole table to validate it while holding ACCESS EXCLUSIVE.
Instead of
Section titled “Instead of”ALTER TABLE orders ADD CONSTRAINT orders_total_positive CHECK (total >= 0);ALTER TABLE orders ADD CONSTRAINT orders_total_positive CHECK (total >= 0) NOT VALID;ALTER TABLE orders VALIDATE CONSTRAINT orders_total_positive;To skip this rule for one statement, put -- pgdeadbolt-ignore add-check-validated on the line above it.