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

Dmitry Romanoff - Oct 26 '23 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player