RECHECK is a PostgreSQL-specific maintenance command that tells the server to verify that existing data still meets the rules defined by a constraint or index that was earlier created with the NOT VALID clause or that relies on a lossy access method (GiST, GIN, BRIN, SP-GiST). During normal query execution PostgreSQL already performs row-level rechecks for lossy indexes, but the RECHECK command lets you do it proactively and in bulk. For constraints, it upgrades them from NOT VALID to VALID without recreating the object from scratch. RECHECK scans the target rows, applies the original predicate, and marks the object as validated when no violations are found. If any row fails, the command aborts and reports the first offending row. Because data is scanned and checked, RECHECK can be I/O intensive and should usually be run during off-peak hours. RECHECK does not rebuild the index structure or alter query plans; it only guarantees logical correctness.
ALTER TABLE VALIDATE CONSTRAINT, CREATE CONSTRAINT NOT VALID, REINDEX, ANALYZE, CHECK constraints
PostgreSQL 12
The command aborts, no changes are committed, and PostgreSQL reports the first offending row so you can fix or remove it.
No. It only guarantees correctness. To improve performance, consider REINDEX, CLUSTER, or ANALYZE.
Yes. Like any SQL statement, it can be cancelled with `pg_cancel_backend` or by terminating the session, though partial work is rolled back.
Yes. If it completes successfully, the validation is committed. If it fails or is cancelled, all effects are rolled back.