SQL · performance
index-concurrently
sql:index-concurrently CREATE INDEX without CONCURRENTLY — locks the table against writes.
- Code
- SARJ108
- Default
- error
- Fix
- none
- Languages
- sql
Why
Building an index normally blocks writes to an existing PostgreSQL table for the duration of the build.
Fix
Use CREATE INDEX CONCURRENTLY in a nontransactional migration.
Before / after
Executed by this rule’s unit tests.
Before
Blocking index build on an existing table
CREATE INDEX users_email_idx ON users(email);
After
Concurrent index build
CREATE INDEX CONCURRENTLY users_email_idx ON users(email);
Limits
- Indexes on tables created earlier in the same file are exempt because no concurrent writers exist yet.