VALIDATE CONSTRAINT verifies that all existing rows satisfy a NOT VALID constraint without recreating it.
VALIDATE CONSTRAINT checks every existing row against a previously created constraint that was declared NOT VALID. If all rows pass, PostgreSQL flips the constraint status to VALID, making it fully enforceable for future inserts or updates.
Run it after you add CHECK, FOREIGN KEY, or UNIQUE constraints with NOT VALID during peak-traffic periods. This lets you defer the heavy scan to a maintenance window, avoiding long blocking locks.
You can list several constraints in one ALTER TABLE statement separated by commas. PostgreSQL scans the table only once, saving I/O and lock time.
PostgreSQL takes a SHARE UPDATE EXCLUSIVE lock. This blocks concurrent ALTER TABLE commands but allows SELECT, INSERT, UPDATE, and DELETE, so your app keeps running.
Create constraints NOT VALID during high load, schedule VALIDATE CONSTRAINT during low-traffic windows, and batch multiple validations together. Always monitor lock wait events.
Yes. Use pg_cancel_backend(pid) on the backend PID performing the validation. Partial progress is not saved, so you must rerun later.
No. It only scans existing rows. However, UNIQUE or PRIMARY KEY constraints may build an index if it was not created earlier.