Add method for creating foreign keys concurrently
This method allows one to create foreign keys without blocking access to the source table, but only on PostgreSQL. When creating a regular foreign key the "ALTER TABLE" statement used for this won't return until all data has been validated. This statement in turn will acquire a lock on the source table. As a result this lock can be held for quite a long amount of time, depending on the number of rows and system load. By breaking up the foreign key creation process in two steps (creation, and validation) we can reduce the amount of locking to a minimum. Locking is still necessary for the "ALTER TABLE" statement that adds the constraint, but this is a fast process and so will only block access for a few milliseconds.
Showing
Please register or sign in to comment