May 2018
Intermediate to advanced
576 pages
30h 25m
English
Take a query that needs to do a big chunk of work, such as this:
\timingSELECT count(*) FROM accounts;count---------1000000(1 row)Time: 261.652 msSET 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 and 10, parallel query only works for read-only queries, so only SELECT statements that do not contain the FOR clause (for example, SELECT ... FOR UPDATE). In addition, a parallel query can only use functions or aggregates that are marked as PARALLEL SAFE. No user-defined functions are marked ...