postgres=# show max_worker_processes ;
max_worker_processes
———————-
128
(1 row)
2、所有会话同时执行并行计算的并行度足够大
postgres=# set max_parallel_workers=64;
SET
3、单个QUERY中并行计算NODE开启的WORKER=24
postgres=# set max_parallel_workers_per_gather=24;
4、所有表和索引扫描允许并行
postgres=# set min_parallel_table_scan_size=0;
postgres=# set min_parallel_index_scan_size=0;
5、并行计算优化器成本设置为0
postgres=# set parallel_tuple_cost=0;
postgres=# set parallel_setup_cost=0;
6、设置表级并行度为24
postgres=# alter table pa set (parallel_workers=24);
ALTER TABLE
7、效果,强制24并行。
postgres=# explain (analyze) select count(*) from pa;
QUERY PLAN
————————————————————————————————————————————-
Finalize Aggregate (cost=1615.89..1615.89 rows=1 width=8) (actual time=81.711..81.711 rows=1 loops=1)
-> Gather (cost=1615.83..1615.83 rows=24 width=8) (actual time=81.572..90.278 rows=25 loops=1)
Workers Planned: 24
Workers Launched: 24
-> Partial Aggregate (cost=1615.83..1615.83 rows=1 width=8) (actual time=58.411..58.411 rows=1 loops=25)
-> Parallel Seq Scan on pa (cost=0.00..712.71 rows=416667 width=0) (actual time=0.012..35.428 rows=400000 loops=25)
Planning Time: 0.449 ms
Execution Time: 90.335 ms
(8 rows)