The idea · Lab 3.5.3Three GUCs work together to bound parallel query: max_worker_processes caps the total background worker processes PostgreSQL may ever launch for any purpose, max_parallel_workers caps how many of those may be used for parallel query specifically, and max_parallel_workers_per_gather caps how many any single query's Gather node may request. All three already default to real, sane values on this server (8, 8, and 2), which this lab checks directly rather than assuming.
The real constraint this lab has to be honest about is not any GUC at all — it is that nproc on this VM reports exactly 1, confirmed back in Certificate 3's very first block. A parallel plan can still genuinely build here — real worker processes really launch, real work really gets divided — but with only one physical core to actually run on, that division has nothing real to parallelize onto, and the coordination overhead becomes a net cost rather than a net win, exactly as measured directly back in Lesson 3.1.5. This lab re-confirms that finding on a different query shape, and adds the curriculum's other real, checkable claim: a genuinely small table declines parallelism entirely, regardless of hardware.
The Three GUCs, Checked Together
SHOW max_worker_processes; -- 8
SHOW max_parallel_workers; -- 8
SHOW max_parallel_workers_per_gather; -- 2
All three already at real, sane defaults on this server — max_worker_processes bounds the total background workers PostgreSQL may ever launch for anything; max_parallel_workers bounds how many of those go to parallel query; max_parallel_workers_per_gather bounds any one query's own request.
A Real Parallel Plan, Measured Honestly
SET max_parallel_workers_per_gather = 0;
EXPLAIN (ANALYZE, TIMING OFF) SELECT category, sum(val) FROM sql_parallel_demo GROUP BY category;
-- HashAggregate + Seq Scan, Execution Time: 1619.553 ms
SET max_parallel_workers_per_gather = 4;
SET parallel_setup_cost = 0; SET parallel_tuple_cost = 0; -- forced, diagnostic only
EXPLAIN (ANALYZE, TIMING OFF) SELECT category, sum(val) FROM sql_parallel_demo GROUP BY category;
Finalize GroupAggregate
-> Gather Merge
Workers Planned: 1
Workers Launched: 1
-> Sort
-> Partial HashAggregate
-> Parallel Seq Scan on sql_parallel_demo
Execution Time: 1767.936 ms
A genuine parallel plan — a real worker process launches and does real, divided work. And it is slower, not faster, than the serial version: 1767.936 ms versus 1619.553 ms. This is the same honest single-vCPU finding already measured directly in Lesson 3.1.5, confirmed again here on a different query shape — with only one real physical core, the coordination overhead of splitting work across processes has no genuine concurrency underneath it to pay that cost back.
A Genuinely Small Table, Correctly Declining
SET max_parallel_workers_per_gather = 4;
EXPLAIN SELECT sum(val) FROM sql_parallel_small; -- 50 rows
Aggregate
-> Seq Scan on sql_parallel_small (cost=0.00..1.50 rows=50 width=12)
Still fully serial, even with 4 workers allowed — parallel_tuple_cost and the other parallel cost GUCs correctly recognize that a 50-row table is nowhere near large enough to be worth the coordination overhead, on any hardware.
Key concepts
parallel_setup_cost / parallel_tuple_cost
Cost constants the planner adds to account for the real overhead of launching parallel workers (parallel_setup_cost) and passing each row back through the Gather node (parallel_tuple_cost). Zeroing them out, as this lab does, removes that overhead from the planner's calculation entirely — a diagnostic technique for forcing a parallel plan to appear so it can be inspected and measured, never a setting to leave changed on a production server, since it would make the planner blind to the coordination overhead that genuinely exists.
Workers Planned vs Workers Launched
Workers Planned is how many parallel workers the planner intended to use for a given Gather node; Workers Launched is how many the operating system actually started at execution time. The two can differ if background worker slots are unavailable at that moment — checking both is how to confirm a parallel plan is not just theoretically chosen but genuinely executed with real worker processes.
What to remember
- max_worker_processes, max_parallel_workers, and max_parallel_workers_per_gather work together as three progressively narrower caps — check all three, not just one
- A forced parallel plan on this VM genuinely launches real worker processes and does real divided work, but measures slower than serial because only one physical core actually exists to run them on
- This single-vCPU result is specific to this VM's real hardware — the same forced plan would very likely be faster on genuine multi-core hardware, which is why measuring on the actual target machine matters more than trusting a benchmark from elsewhere
- A genuinely small table correctly declines parallelism regardless of how many workers are allowed, on any hardware — this is the planner's cost model working as intended, not a limitation to work around
- Zeroing parallel_setup_cost and parallel_tuple_cost is a diagnostic technique for forcing a parallel plan into view, never a setting to leave changed on a real server