Constraints
ADD CONSTRAINT ... CHECK ... NOT VALID
Lock mode ACCESS EXCLUSIVE
Risk LOW
Blocks reads, writes, other DDL
pgfence rule
add-constraint-check-not-valid ALTER TABLE orders ADD CONSTRAINT orders_status_check CHECK (status IN ('pending','paid','shipped')) NOT VALID; What this does
NOT VALID skips the validation scan, so this is a brief, metadata-only ACCESS EXCLUSIVE lock. New and updated rows are enforced immediately; existing rows are only checked once a follow-up VALIDATE CONSTRAINT runs.
Safe rewrite
Already using the safe pattern. Follow up with VALIDATE CONSTRAINT
ALTER TABLE orders VALIDATE CONSTRAINT orders_status_check;