11

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 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?

1
  • It's max_parallel_workers = 0, not max_parallel_works = 0
    – Daniel
    Commented Nov 19, 2023 at 8:27

1 Answer 1

17

From the docs,

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 ms
3
  • how can we find the current settings of parallel configurations like the current value of max_parallel_workers_per_gather?
    – Surya
    Commented Jan 6, 2020 at 7:17
  • 3
    SHOW max_parallel_workers_per_gather; Commented Jan 6, 2020 at 13:54
  • 1
    @Surya also worth noting you can see all settings in the pg_settings table select * from pg_settings where name like '%parallel%'
    – jkdba
    Commented Oct 8, 2020 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.