Constraints

VALIDATE CONSTRAINT (standalone)

Lock mode SHARE UPDATE EXCLUSIVE
Risk LOW
Blocks other DDL
pgfence rule validate-constraint
ALTER TABLE orders VALIDATE CONSTRAINT orders_customer_id_fkey;

What this does

The entire reason the NOT VALID pattern works. Postgres's own documentation explains it does not need to lock out concurrent updates during validation, since new rows are already enforced; only pre-existing rows need checking. SHARE UPDATE EXCLUSIVE does not conflict with ROW EXCLUSIVE, so ordinary INSERT/UPDATE/DELETE traffic keeps running through a scan that can take minutes on a large table. It does conflict with itself and with SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE, so a second VALIDATE CONSTRAINT, CREATE INDEX CONCURRENTLY, or VACUUM on the same table still has to wait.

Read more

More in Constraints