As has been commented, CONCURRENTLY is not a property of the index, but an instruction to create the index without blocking concurrent writes. The resulting index does not remember that option in any way. Read the chapter "Building Indexes Concurrently" in the manual.
Creating indexes on big tables can take a while. The system table
pg_stat_progress_create_index can be queried for progress reporting. While that is going on, CONCURRENTLY is still reflected in the command column.
To your consolation: once created, all indexes are "concurrent" anyway, in the sense that they are maintained automatically without blocking concurrent reads or writes (except for UNIQUE indexes that prevent duplicates.)
What is the difference between CREATE INDEX and CREATE INDEX CONCURRENTLY in PostgreSQL? - Database Administrators Stack Exchange
how to create big indexes
Don't rely on IF NOT EXISTS for concurrent index creation in PostgreSQL
Support `CREATE INDEX CONCURRENTLY` (PostgreSQL)
The difference is in "how it works". It is about "How long?" and "Can we block the indexed table changes for the indexing time?". The results are the same.
Any CREATE INDEX should scan its table, sort values from your target field, and store the result.
The regular one LOCKs the table. It means no INSERT, UPDATE, or DELETE query can not be processed until the index creation is finished. On Production, depending on the data amount, it could take a very long time. The change queries can timeout, and a service could be partially inoperable. SELECT queries work normally with this lock. But from the total DB processing time, such a request will be optimal and fast. It takes only 1 full table scan and sorting.
The CONCURRENT one doesn't make a LOCK. So any updates can flow into the table. The change queries will flow as expected. But indexing will take much more time. This operation will take at least 2 full table scans and sorting. If during the operation there were changes then - update the new index data and scan again. This step can be iterated multiple times. So its execution is not optimal and takes much more time and resources, than the base one.
Hope, this will help.
The difference is only in the way the indexes are built, but once that is done, the results is the same. A concurrently created index can have some bloat, but that difference will even out after a while.
Hello experts,
We have a few tables having size ~5TB and are partitioned on a timestamp column. They have ~90 partitions in them and are storing 90 days of data. We want to create a couple of indexes on those tables. They are getting the incoming transactions(mainly inserts) 24/7 , which are mostly happening on the current day/live partition. Its RDS postgres version 15.4. So in this situation
Should we go with below i.e one time create index command on the table..
CREATE INDEX CONCURRENTLY idx1 ON tab(column_name);
Or
create index on individual partitions from different sessions, say for example create indexes on 30 partitions each from three different sessions so as to finish all the 90 partitions faster?
CREATE INDEX CONCURRENTLY idx1 ON tab_part1(column_name);
CREATE INDEX CONCURRENTLY idx1 ON tab_part2(column_name);..........
Basically I have three questions:
1)If we can do this index creation activity online without impacting the incoming transactions or do we have to take down time for this activity?
2)If we can't do it online then , what is the fastest method to do this index creation activity ?
3)Should we change the DB parameters in a certain way to make the process faster? We have currently set below parameters
max_parallel_workers-16
max_parallel_maintenance_workers-2
maintenance_work_mem- 4GB