Using parallel query
PostgreSQL 9.6 introduces parallel query, after many years of development.
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 you'll gain more by thinking about better indexing strategies.
How to do it...
Take a query that needs to do a big chunk of work, such as this:
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 that we didn't need to change the query at all.
In PostgreSQL 9.6, parallel query only works for read-only queries, so only SELECT
statements that do not...