validating-foreign-key-constraint-on-existing-rows (US012)#
Automatic fix is available.
What it does#
Checks validating foreign key constraint on existing rows.
Why not?#
Adding a foreign key constraint to an already populated table will have to scan and validate that there are no violating records in the table, causing the table to be locked in which no other operations can be performed on the table for the duration of the validation. This will cause downtime if the table is concurrently being accessed by other clients.
When should you?#
If the table is empty. If the table is not empty but is not being concurrently accessed.
Use instead:#
- Add the foreign key constraint without validation.
- Validate the constraint in a separate transaction.