DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on

Postgres. CREATE INDEX concurrently <index_name> ON <table_name> ... takes too long.

Postgres. CREATE INDEX concurrently ON ... takes too long.

Check that you see the index as invalid when running \d+ . If you don't have the index, it means its creation didn't start. There is some process that blocks the index creation.

To find out which process blocks the creation of an index run the following SQL command:

select pid, 
       usename, 
       pg_blocking_pids(pid) as blocked_by, 
       query as blocked_query
from pg_stat_activity
where cardinality(pg_blocking_pids(pid)) > 0;
Enter fullscreen mode Exit fullscreen mode

Terminate the session that blocks index creation.

Wait till the index is created.

Top comments (0)