5

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)
1
  • 1
    First, check to see if the CREATE INDEX statement is actually being blocked by another process/transaction: wiki.postgresql.org/wiki/Lock_Monitoring. Please update your post with your findings Commented Oct 31, 2019 at 16:29

1 Answer 1

10

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 (e.g. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.