简体   繁体   中英

Postgres index creation time

Postgres is creating simple index more than 2 days. Where can I see a log, or something about status index creation? Before this situation I've created index couple times and it took about an hour or less. I have about 5.5m rows and execute next command:

CREATE INDEX collapse_url ON tablle (url, collapse)

There are two possibilities:

  1. The CREATE INDEX statement is waiting for a lock.

    You should be able to see that in the pg_stat_activity view.

    If that is your problem, end all concurrent long running transactions (eg using pg_terminate_backend ).

  2. The CREATE INDEX statement is truly taking very long (unlikely with a few million rows).

    In that case, you can speed up processing by increasing maintenance_work_mem before you create the index.

There have been relevant improvements in this area in recent versions:

  • PostgreSQL v11 introduced parallel index builds.

  • PostgreSQL v12 introduced the view pg_stat_progress_create_index to monitor the progress of CREATE INDEX .

  • PostgreSQL v12 also introduced CREATE INDEX CONCURRENTLY to avoid a long ACCESS EXCLUSIVE lock on the table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM