Using parallel query
PostgreSQL now has an increasingly effective parallel query feature.
Response times from long-running queries can be improved by the use of parallel processing. The concept is that if we divide a large task up into multiple smaller pieces then we get the answer faster, but we use more resources to do that.
Very short queries won't get faster by using parallel query, so if you have lots of those you'll gain more by thinking about better indexing strategies. Parallel query is aimed at making very large tasks faster, so it is useful for reporting and business intelligence (BI) queries.
How to do it…
Take a query that needs to do a big chunk of work, such as the following:
\timing SET max_parallel_workers_per_gather = 0; SELECT count(*) FROM big; count --------- 1000000 (1 row) Time: 46.399 ms SET max_parallel_workers_per_gather = 2; SELECT count(*) FROM big; count --------- 1000000 (1 row) Time: 29.085 ms
By setting the...