4

I have a postgres table with 3 columns that has 4 million rows and growing. When I created the table I intended to create a btree index on one of the columns, but I forgot to do so. I can use the CREATE INDEX command to create the index now, but I think that will lock up the db. Since I have data coming in every second, I would like to avoid that. I noticed that there is an option called CONCURRENTLY. Is that what I should use? Does it have any other effects that I should be aware of?

Thanks!

2 Answers 2

4

Yes you can use CREATE INDEX CONCURRENTLY idx_xyz ON sometable(key_a, key_b);

However caveats apply: you have to look yourself, whether it succeded, and possibly re-try.

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

Comments

3

Yes CONCURRENTLY will allow your table to remain in use while the index is building. The performance implications are difficult to predict and will vary based on the load on the table and how big the index is.

Whenever we had to add an index to an always-on production database we chose to schedule downtime with our clients instead of risking using the online indexing feature because it's less predictable and could cause an outage for a different reason.

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.