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 we divide a large task up into multiple smaller pieces. 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 queries.
How to do it…
Take a query that needs to do a big chunk of work, such as the following:
\timing SELECT count(*) FROM accounts; count --------- 1000000 (1 row) Time: 261.652 ms SET max_parallel_workers_per_gather = 8; SELECT count(*) FROM accounts; count --------- 1000000 (1 row) Time: 180.513 ms
By setting the max_parallel_workers_per_gather
parameter, we've improved performance using parallel query. Note...