snippetsqlModerate
How can I disable parallel queries in PostgreSQL?
Viewed 0 times
postgresqlcandisableparallelhowqueries
Problem
I want to benchmark some things in PostgreSQL. When I do this I normally turn off some of the features the database is currently using, just for my session, to see what the second-best plan is.
Though setting
I know it says
Though setting
max_parallel_works = 0 , I still get a parallel plan.QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Gather (cost=1000.00..120892.01 rows=1000 width=15) (actual time=0.444..4781.539 rows=666667 loops=1)
Workers Planned: 2
Workers Launched: 0
-> Parallel Seq Scan on foo (cost=0.00..119792.01 rows=417 width=15) (actual time=0.102..4711.530 rows=666667 loops=1)
Filter: (lower(x) ~~ '%999.com'::text)
Rows Removed by Filter: 9333333
Planning time: 0.124 ms
Execution time: 4801.491 ms
(8 rows)I know it says
Workers Launched: 0. But, I would like that to look like a pre-Parallel plan where the plan itself is not even planned to be parallel. How can I accomplish this?Solution
From the docs,
So to disable the parallel query planning use,
You can see that here, same query,
max_parallel_workers_per_gather (integer) Sets the maximum number of workers that can be started by a single Gather or Gather Merge node. Parallel workers are taken from the pool of processes established by max_worker_processes, limited by max_parallel_workers. Note that the requested number of workers may not actually be available at run time. If this occurs, the plan will run with fewer workers than expected, which may be inefficient. The default value is 2. Setting this value to 0 disables parallel query execution.So to disable the parallel query planning use,
SET max_parallel_workers_per_gather = 0;You can see that here, same query,
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Seq Scan on foo (cost=0.00..207292.03 rows=1000 width=15) (actual time=0.082..4715.721 rows=666667 loops=1)
Filter: (lower(x) ~~ '%999.com'::text)
Rows Removed by Filter: 9333333
Planning time: 0.083 ms
Execution time: 4736.202 msCode Snippets
SET max_parallel_workers_per_gather = 0;QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Seq Scan on foo (cost=0.00..207292.03 rows=1000 width=15) (actual time=0.082..4715.721 rows=666667 loops=1)
Filter: (lower(x) ~~ '%999.com'::text)
Rows Removed by Filter: 9333333
Planning time: 0.083 ms
Execution time: 4736.202 msContext
StackExchange Database Administrators Q#226654, answer score: 15
Revisions (0)
No revisions yet.