In PostgreSQL, if you want to create an index non-blocking (i.e., without locking the table for writes for a long time), the standard and safe way is to use:
sql
CREATE INDEX CONCURRENTLY idx_name ON table_name (column_name);
This avoids blocking INSERT, UPDATE, and DELETE operations on the table while the index is being built.
But what if you don't want to useCONCURRENTLY?
If you're avoiding CONCURRENTLY due to concerns like:
Risk of leaving behind invalid indexes if interrupted
Wanting a simpler index creation process
Avoiding increased I/O or performance impact during concurrent index builds
...but still want non-blocking behavior, then your options are limited because PostgreSQL does not offer a non-blocking index creation method outside of CONCURRENTLY.
Why CONCURRENTLY is the only option:
When you do:
sql
CREATE INDEX idx_name ON table_name (column_name);
It takes a SHARE lock on the table and blocks all writes until the index build completes. On large tables or slow disks, this can be very disruptive.
Whereas:
sql
CREATE INDEX CONCURRENTLY idx_name ON table_name (column_name);
Builds the index without taking a strong lock, allowing normal DML to proceed.
Alternatives / Workarounds (if you really can't use CONCURRENTLY):
There are no direct alternatives that avoid blocking entirely, but here are some approaches to reduce impact:
1. Create Index During Low Traffic Window
Schedule the index creation during off-peak hours when blocking won’t affect users.
2. Use a Smaller Subset with a Partial Index
If applicable, create a smaller partial index that covers only recent data:
sql
CREATE INDEX idx_recent ON table_name (column_name) WHERE created_at > NOW() - INTERVAL '7 days';
Smaller index = faster creation = shorter lock time.
3. Upgrade PostgreSQL
Newer versions of PostgreSQL have improved index building performance. For example:
Logical Decoding Improvements
Parallel Index Builds
Better Vacuum/Index Maintenance
Make sure you’re on at least PostgreSQL 14+ for best results.
4. Use Logical Replication or a Shadow Table
For extreme availability requirements, consider more advanced patterns like:
Building the index on a standby replica
Using logical replication to apply changes to a shadow table, then swapping
But these are complex and typically used only in high-availability critical systems.
Summary
Option
Blocking?
Safe from interruption?
CREATE INDEX
✅ Yes
❌ No
CREATE INDEX CONCURRENTLY
❌ No
✅ Yes
💡 Bottom Line: If you need non-blocking index creation in PostgreSQL, there's no alternative to using CONCURRENTLY. You must weigh the trade-offs and manage the risks accordingly (e.g., monitoring for failed builds or invalid indexes).
Let me know if you'd like help managing CONCURRENTLY safely or checking for failed index builds.