B
B
BestJS2019-03-15 16:04:44
PostgreSQL
BestJS, 2019-03-15 16:04:44

How to speed up index creation in PosgGreSQL?

Basically the question is in the title.
Here are some features I noticed:
1) PSQL creates the index in single threaded mode. This is 10% of all cpu performance.
2) As I understand it, it reads the database, processes it and compresses it. (In single-threaded mode, this is very slow.)
3) Due to the fact that it processes data slowly, it does not use the full speed of the ssd on which the base is located.
The text column to which I want to make an index will weigh more than 600GB.
to make an index according to my calculations, it will be from 3-4 days
There are several ideas on how to speed up, but I did not find how to implement them
Make a lot of threads on the cpu. If you load the percent by 100%, then we get a 10 times increase in performance
To make multi-threading on gpu, but this is already from a series of fiction.
I would be grateful for any advice

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-03-15
@BestJS

What index? Perhaps a surprise, but they are very different.
psql is a client, it doesn't create indexes at all.
postgresql - since version 11 multi-threaded creation of btree. Although, probably, it would be more accurate to say sorting.
Not base, and the table. One full seqscan for create index (with write lock) or two seqscan for create index concurrently (without table lock).
Doesn't compress anything.
Well, depending on what disks. It is quite possible to puzzle cheap SSDs with large numbers of temporary files and one CPU core, I have seen this as well.
To speed up the construction of a large index, maintenance_work_mem is needed. How much is not a pity. 10, 20, 30, 100GB.
On postgresql 11 - plus set the number of workers max_parallel_maintenance_workers, max_worker_processes, max_parallel_workers
If you want to participate in the development of postgresql itself - welcome to the pgsql-hackers mailing list. You can read how parallel create index was done at the links from the commit .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question