EXPLAIN ANALYZE shows Workers Planned: 2, Workers Launched: 0 —
but only if you run it while the system is under load.
Run it on an idle box and workers launch just fine.
The problem disappears. You find nothing.
This is not a debugging tool for worker exhaustion.
You need cumulative counters, not point-in-time plans.
-- Cluster-level: is the pool being starved?
SELECT datname,
parallel_workers_to_launch,
parallel_workers_launched,
parallel_workers_to_launch
- parallel_workers_launched AS gap
FROM pg_stat_database
WHERE datname = current_database();
-- Query-level: which queries are losing workers?
SELECT query,
parallel_workers_to_launch,
parallel_workers_launched,
parallel_workers_to_launch
- parallel_workers_launched AS gap
FROM pg_stat_statements
WHERE parallel_workers_to_launch > 0
ORDER BY gap DESC
LIMIT 10;
CREATE TABLE events_part (...) PARTITION BY RANGE (created_at);
-- 12 monthly partitions, growing every month
SELECT event_type, count(*) FROM events_part GROUP BY event_type;
Finalize GroupAggregate
-> Gather (workers planned: 2)
-> Parallel Append
-> Parallel Seq Scan on events_p202504
-> Parallel Seq Scan on events_p202505
... 12 partitions ...
2 workers shared across 12 partitions — not 2 per partition.
But the number of workers requested scales with partition count.
The number of workers requested scales roughly logarithmically with partition count.
| Partitions | Workers requested |
|---|---|
| 6 | 2 |
| 12 | 3 |
| 24 | 4 |
| 48 | 5 |
That number is capped by max_parallel_workers_per_gather — but as partitions grow, the planner keeps asking for more. Nobody noticed the partition count doubled. Nobody re-audited the plan. The query just got slower and hungrier.
Parallel features compound. Audit them when your data shape changes.
How do you find this in your fleet today?
-- Live: are workers being starved right now?
SELECT count(*) FILTER (WHERE backend_type = 'parallel worker') AS workers,
count(*) FILTER (WHERE state = 'active') AS active_clients
FROM pg_stat_activity;
-- Live: who is waiting on parallel infrastructure?
SELECT pid, wait_event_type, wait_event, query
FROM pg_stat_activity
WHERE wait_event IN ('BgWorkerShutdown', 'BgWorkerStartup', 'ExecuteGather', 'ParallelFinish');
If workers is regularly at max_parallel_workers, you have a problem.
Sessions on ExecuteGather are blocked waiting for parallel results.
Sessions on ParallelFinish are waiting for workers to finish and clean up.
Sessions on BgWorkerStartup / BgWorkerShutdown are in worker lifecycle overhead.
-- Cumulative: which queries are losing workers?
SELECT query,
parallel_workers_to_launch,
parallel_workers_launched,
parallel_workers_to_launch
- parallel_workers_launched AS gap
FROM pg_stat_statements
WHERE parallel_workers_to_launch > 0
ORDER BY gap DESC
LIMIT 10;
-- Cumulative: is the pool being starved cluster-wide?
SELECT datname,
parallel_workers_to_launch,
parallel_workers_launched,
parallel_workers_to_launch
- parallel_workers_launched AS gap
FROM pg_stat_database
WHERE datname = current_database();
A persistent gap means queries are silently running parallel plans on a single core.
Parallel query has its place.
If a query, data model, and data distribution are designed correctly,
it can provide tangible benefits.
The trick is ensuring you are in control of the parallelism
in use at any given time — globally, across the cluster.
The problem with every partial fix is the same:
you can't bound total worker count across concurrent sessions.
-- postgresql.conf / ALTER SYSTEM
ALTER SYSTEM SET max_parallel_workers_per_gather = 0;
SELECT pg_reload_conf();
This is not the nuclear option. This is the baseline.
Parallel query is now off for all workloads, all users, all tables.
Nothing happens without your explicit permission.
Per-query, using session variables:
SET max_parallel_workers_per_gather = 4;
SELECT count(*) FROM events WHERE created_at > now() - interval '1 year';
RESET max_parallel_workers_per_gather;
Per-query, using pg_hint_plan:
/*+ Parallel(events 4 hard) */
SELECT count(*) FROM events WHERE created_at > now() - interval '1 year';
hard means use exactly 4 workers — not "up to 4".
You asked for it. You got it. Nothing surprises you.
pg_hint_plan docs: https://pg-hint-plan.readthedocs.io/en/latest/hint_details.html
Only if you can guarantee a max concurrency count.
-- Analytical user gets parallelism, OLTP users don't
ALTER ROLE analyst SET max_parallel_workers_per_gather = 4;
-- Or scope to a specific database
ALTER DATABASE analytics SET max_parallel_workers_per_gather = 4;
If 10 analyst sessions can run concurrently and each gets 4 workers,
you need max_parallel_workers ≥ 40. Know your math before you enable.
ALTER TABLE events SET (parallel_workers = 4);
This caps workers per query on this table.
It does not cap total workers across all concurrent sessions.
10 sessions hit events simultaneously → up to 40 workers.
You have no cluster-level guarantee.
And when that 11th session arrives and the worker pool is exhausted?
Your analyst gets no error. No warning. No slow query log entry.
They get a parallel plan running on a single CPU —
untraceable, silent, and slower than if parallelism had never been enabled.
In a mixed workload system, per-table settings trade
one instability for another.
pg_hint_plan.pg_stat_activity.Workers Launched: 0 — the silent parallel plan with no workers.Parallelism is not opt-in by default.
Make it opt-in by design.
Scott Mead · [email protected]