简体   繁体   中英

Creating indexes on big tables - postgresql 9.6

I'm trying to create some regular indexes on a big table (26G), but it takes a lot of time - more than 2 hours. Every index is taking about 11 minutes.

Maybe I'm wrong and I should concentrate on improving the time it takes me to load the data into postgres from oracle ( oracle_fdw ). I preform a lot of inserts into local_postgresql_table select * from remote_oracle_table (about 200G), which also takes a lot of time.

If there is a way to change one of the parameters to improve the performance, I would be happy to hear how. Running this query on 26G takes two hours.

Is there a way to improve this operation? Is there a way to improve this operation by improving the hardware (I didn't see that the server is overloaded)?

The parameters that I configured:

min_parallel_relation_size = 200MB
max_parallel_workers_per_gather = 5 
max_worker_processes = 8 
effective_cache_size = 2500MB
work_mem = 16MB
maintenance_work_mem = 1500MB
shared_buffers = 1500MB
RAM : 5G

Visit this blog for the Example of Parallel Query Processing:

For Parallel Sequential Scanning, in background multiple workers or CPU threads are responsible for executing one single query. We can easily set Parallel Sequential parameter's value can execute your query 10 times faster.

Using max_worker_processes parameter, in PostgreSQL 9.6, You can change the Process Workers parameter value which is default 8.

One issue with creating X multiple indexes is that if the table size exceeds your cache size then you cannot avoid performing X physical reads of your table.

Many years ago, I got round this on Oracle by starting the builds of multiple indexes in different sessions at the same time. This meant that there was only one physical read of each block for each batch of indexes being created.

The downside is that you need more sort memory to be able to effectively do this.

Might be worth a try.

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