The symptom
A parallel plan splits a scan, join or aggregate over several workers. Three things go wrong with it, and all three are written in the plan. PostgreSQL can plan for workers it does not get at run time. SQL Server can hand almost every row to one thread while the others sit idle. And SQL Server can be stopped from building a parallel plan at all, in which case the plan records why.
O query plan viewer flags each of these. The examples use a shop schema with 400,000 orders in three statuses: 384,000 shipped, 12,000 cancelled and 4,000 pending.
Diagnose it
PostgreSQL: workers planned and workers launched
Cada Gather ou Gather Merge node in an EXPLAIN ANALYZE plan prints two numbers. Workers Planned is what the planner costed the plan for. Workers Launched is what the node got when it ran.
EXPLAIN (ANALYZE, TIMING OFF, SUMMARY OFF, BUFFERS OFF)
SELECT status, count(*) FROM orders GROUP BY status;
Finalize GroupAggregate (cost=7982.08..7982.96 rows=3 width=16) (actual rows=3.00 loops=1)
Group Key: status
-> Gather Merge (cost=7982.08..7982.89 rows=7 width=16) (actual rows=9.00 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Sort (cost=6982.06..6982.06 rows=3 width=16) (actual rows=3.00 loops=3)
Sort Key: status
Sort Method: quicksort Memory: 25kB
Worker 0: Sort Method: quicksort Memory: 25kB
Worker 1: Sort Method: quicksort Memory: 25kB
-> Partial HashAggregate (cost=6982.00..6982.03 rows=3 width=16) (actual rows=3.00 loops=3)
Group Key: status
Batches: 1 Memory Usage: 32kB
Worker 0: Batches: 1 Memory Usage: 32kB
Worker 1: Batches: 1 Memory Usage: 32kB
-> Parallel Seq Scan on orders (cost=0.00..6148.67 rows=166667 width=8) (actual rows=133333.33 loops=3)
The row counts under a Gather are averages per process. rows=133333.33 loops=3 on the scan means three processes (two workers and the leader) read 400,000 rows between them.
Workers come out of a pool shared by the whole server. When the pool is empty the query still runs, with fewer workers or with none. You can see what that looks like by emptying the pool for your own session:
SET max_parallel_workers = 0;
EXPLAIN (ANALYZE, TIMING OFF, SUMMARY OFF, BUFFERS OFF)
SELECT status, count(*) FROM orders GROUP BY status;
RESET max_parallel_workers;
Finalize GroupAggregate (cost=7982.08..7982.96 rows=3 width=16) (actual rows=3.00 loops=1)
Group Key: status
-> Gather Merge (cost=7982.08..7982.89 rows=7 width=16) (actual rows=3.00 loops=1)
Workers Planned: 2
Workers Launched: 0
-> Sort (cost=6982.06..6982.06 rows=3 width=16) (actual rows=3.00 loops=1)
Sort Key: status
Sort Method: quicksort Memory: 25kB
-> Partial HashAggregate (cost=6982.00..6982.03 rows=3 width=16) (actual rows=3.00 loops=1)
Group Key: status
Batches: 1 Memory Usage: 32kB
-> Parallel Seq Scan on orders (cost=0.00..6148.67 rows=166667 width=8) (actual rows=400000.00 loops=1)
The plan shape is the same, but Workers Launched: 0 e loops=1 on the scan say the leader read all 400,000 rows alone. The plan was costed for three processes and ran on one, so it is slower than its estimate, and sometimes slower than the serial plan the planner would have picked had it known.
PostgreSQL: the three limits
SELECT name, setting, context
FROM pg_settings
WHERE name IN ('max_worker_processes', 'max_parallel_workers',
'max_parallel_workers_per_gather')
ORDER BY name;
name | setting | context
max_parallel_workers | 8 | user
max_parallel_workers_per_gather | 2 | user
max_worker_processes | 8 | postmaster
max_parallel_workers_per_gather caps the workers one Gather node may plan for. max_parallel_workers caps the workers running for parallel queries across all sessions. max_worker_processes is the size of the pool that parallel workers share with other background workers; its postmaster context means a change needs a restart.
To see how many workers are busy right now:
SELECT count(*) AS parallel_workers_running
FROM pg_stat_activity
WHERE backend_type = 'parallel worker';
SQL Server: was the plan allowed to go parallel?
The root of the plan XML carries a DegreeOfParallelism attribute. When something stopped the optimizer from considering a parallel plan, the same element has a NonParallelPlanReason. Capture the actual plan with SET STATISTICS XML ON, or with Include Actual Execution Plan in your client, and look at the QueryPlan element:
SET STATISTICS XML ON;
GO
SELECT MAX(rn)
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Status ORDER BY OrderDate) AS rn
FROM dbo.Orders) AS x
OPTION (MAXDOP 1);
GO
SET STATISTICS XML OFF;
NonParallelPlanReason="MaxDOPSetToOne"
MaxDOPSetToOne is the reason for a MAXDOP 1 hint, for a database scoped MAXDOP of 1 and for a server-wide max degree of parallelism of 1. Two other reasons come from the query itself. An insert into a table variable is always serial:
SET STATISTICS XML ON;
GO
DECLARE @t TABLE (OrderId int, rn bigint);
INSERT INTO @t
SELECT OrderId, ROW_NUMBER() OVER (PARTITION BY CustomerId ORDER BY OrderDate)
FROM dbo.Orders;
GO
SET STATISTICS XML OFF;
NonParallelPlanReason="TableVariableTransactionsDoNotSupportParallelNestedTransaction"
A scalar user-defined function that is not inlined gives TSQLUserDefinedFunctionsNotParallelizable; a seção scalar function guide covers that one.
A plan with DegreeOfParallelism="1" and no reason is different. Nothing blocked it. The optimizer costed the serial plan below cost threshold for parallelism, or found the serial plan cheaper.
SQL Server: rows per thread
In an actual plan each operator lists the rows every thread handled, in RunTimeCountersPerThread elements. A row-mode window function partitioned on a column with three values shows what skew looks like. The hint keeps this example in row mode:
SET STATISTICS XML ON;
GO
SELECT MAX(rn)
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Status ORDER BY OrderDate) AS rn
FROM dbo.Orders) AS x
OPTION (USE HINT('DISALLOW_BATCH_MODE'));
GO
SET STATISTICS XML OFF;
The plan ran with DegreeOfParallelism="7". These are the counters of its Sort, cut down to the thread number and the row count:
<RunTimeCountersPerThread Thread="7" ActualRows="4000" />
<RunTimeCountersPerThread Thread="6" ActualRows="12000" />
<RunTimeCountersPerThread Thread="5" ActualRows="0" />
<RunTimeCountersPerThread Thread="4" ActualRows="384000" />
<RunTimeCountersPerThread Thread="3" ActualRows="0" />
<RunTimeCountersPerThread Thread="2" ActualRows="0" />
<RunTimeCountersPerThread Thread="1" ActualRows="0" />
<RunTimeCountersPerThread Thread="0" ActualRows="0" />
Thread 0 is the coordinator and never carries rows in a parallel zone. Of the seven workers, four got nothing and one sorted 384,000 of the 400,000 rows. The Repartition Streams operator below the sort sends all rows with the same Status to the same thread, and there are only three statuses, so no more than three threads can ever have work. Which thread number gets which status changes from run to run.
The scan at the bottom of the same plan is spread evenly, at 10,000 to 80,000 rows a thread. Skew starts at the exchange that repartitions on a column with few values, or with one value that dominates.
Fix it
PostgreSQL: give the query its workers
If plans often launch fewer workers than planned, the pool is too small for the load. Raise the pool and the parallel share of it together. max_parallel_workers acima max_worker_processes has no effect, and max_worker_processes only changes at a restart:
ALTER SYSTEM SET max_worker_processes = 16;
ALTER SYSTEM SET max_parallel_workers = 16;
If one kind of query should use more workers than the default two, raise the per-node limit for that session. On this table that alone changes nothing, because the planner picks the worker count from the size of the table and settles on two. A storage parameter on the table overrides that choice:
SET max_parallel_workers_per_gather = 4;
ALTER TABLE orders SET (parallel_workers = 4);
EXPLAIN (ANALYZE, TIMING OFF, SUMMARY OFF, BUFFERS OFF, COSTS OFF)
SELECT status, count(*) FROM orders GROUP BY status;
Workers Planned: 4
Workers Launched: 4
-> Parallel Seq Scan on orders (actual rows=80000.00 loops=5)
Both limits apply. With max_parallel_workers_per_gather left at 2, the same table setting still plans two workers. To put both back:
RESET max_parallel_workers_per_gather;
ALTER TABLE orders RESET (parallel_workers);
PostgreSQL: a function that blocks parallelism
When a query you expected to be parallel has no Gather node at all, check the functions it calls. A user-defined function is PARALLEL UNSAFE unless it says otherwise, and one unsafe function makes the whole query serial:
CREATE FUNCTION net_total(t numeric) RETURNS numeric
LANGUAGE plpgsql AS 'BEGIN RETURN t / 1.2; END';
EXPLAIN (COSTS OFF)
SELECT status, sum(net_total(total)) FROM orders GROUP BY status;
HashAggregate
Group Key: status
-> Seq Scan on orders
If the function reads no temporary tables, writes nothing and changes no session state, mark it safe:
ALTER FUNCTION net_total(numeric) PARALLEL SAFE;
EXPLAIN (COSTS OFF)
SELECT status, sum(net_total(total)) FROM orders GROUP BY status;
Finalize GroupAggregate
Group Key: status
-> Gather Merge
Workers Planned: 2
-> Sort
Sort Key: status
-> Partial HashAggregate
Group Key: status
-> Parallel Seq Scan on orders
SQL Server: remove what forces the serial plan
Para MaxDOPSetToOne, find where the 1 comes from: a hint in the query text, the database, or the server.
SELECT name, value FROM sys.database_scoped_configurations WHERE name = 'MAXDOP';
SELECT name, value_in_use FROM sys.configurations
WHERE name IN ('max degree of parallelism', 'cost threshold for parallelism');
For the table variable reason, load a temporary table instead. The insert stays serial but the query that feeds it runs in parallel:
CREATE TABLE #t (OrderId int, rn bigint);
GO
SET STATISTICS XML ON;
GO
INSERT INTO #t
SELECT OrderId, ROW_NUMBER() OVER (PARTITION BY CustomerId ORDER BY OrderDate)
FROM dbo.Orders
OPTION (USE HINT('DISALLOW_BATCH_MODE'));
GO
SET STATISTICS XML OFF;
DegreeOfParallelism="7"
SQL Server: deal with the skew
First measure whether the parallel plan is buying anything. Run the skewed query and its serial twin with SET STATISTICS TIME ON and compare:
SET STATISTICS TIME ON;
GO
SELECT MAX(rn)
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Status ORDER BY OrderDate) AS rn
FROM dbo.Orders) AS x
OPTION (USE HINT('DISALLOW_BATCH_MODE'));
GO
SELECT MAX(rn)
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Status ORDER BY OrderDate) AS rn
FROM dbo.Orders) AS x
OPTION (USE HINT('DISALLOW_BATCH_MODE'), MAXDOP 1);
GO
SET STATISTICS TIME OFF;
On the test server both finished in about 300 ms, and the parallel one used more CPU to get there. When one thread does all the work, seven threads are no faster than one, and a MAXDOP 1 hint on that statement gives the other queries their cores back.
The better fix removes the repartitioning. Here that is batch mode: without the row-mode hint, SQL Server 2025 runs the same query with a Window Aggregate operator that needs no exchange on Status, and it finished in about 70 ms on the same server.
SET STATISTICS TIME ON;
GO
SELECT MAX(rn)
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Status ORDER BY OrderDate) AS rn
FROM dbo.Orders) AS x;
GO
SET STATISTICS TIME OFF;
Where the skew comes from a join or a GROUP BY, look at the column the exchange partitions on. A column with few values, or one value that covers most rows, will always skew.
When to leave it alone
A serial plan is the right plan for a query that finishes in milliseconds; starting workers costs more than it saves. A PostgreSQL query that now and then launches one worker fewer on a busy server is working as designed. And skew on an operator that handles a few thousand rows costs nothing you can measure. Act when the query is slow and the plan shows it was costed for parallel work it did not get.
The checklist
Work through it in order. Each step gives you the evidence for the next one.
- PostgreSQL: compare Workers Planned with Workers Launched on every Gather node.
- Check max_parallel_workers, max_parallel_workers_per_gather and max_worker_processes in pg_settings.
- No Gather node at all: look for a user-defined function that is not marked PARALLEL SAFE.
- SQL Server: read DegreeOfParallelism and NonParallelPlanReason on the QueryPlan element.
- For MaxDOPSetToOne, check the query hint, the database scoped MAXDOP and the server setting.
- Compare ActualRows per thread on the operators above a Repartition Streams exchange.
- Time the query against a MAXDOP 1 run before deciding the parallel plan is worth keeping.
Questions that come up
What does Workers Launched: 0 mean in PostgreSQL?
The plan was built for parallel workers but none were available when it ran, so the leader process did all the work alone. The limit that ran out is max_parallel_workers or max_worker_processes, both shared by every session on the server.
Why are the row counts under a Gather node smaller than the table?
EXPLAIN ANALYZE shows rows per loop, and under a Gather node each participating process counts as one loop. Multiply rows by loops to get the total. A scan that shows rows=133333.33 loops=3 read 400,000 rows.
What is NonParallelPlanReason in a SQL Server plan?
It is an attribute on the QueryPlan element of the plan XML that says why the optimizer could not consider a parallel plan. MaxDOPSetToOne means a hint or a setting limits the query to one thread. Other values point at something in the query, such as a scalar user-defined function or an insert into a table variable.
Does a serial plan always have a NonParallelPlanReason?
No. The attribute appears only when something prevented a parallel plan. A cheap query whose estimated cost is below cost threshold for parallelism gets a serial plan with no reason attached.
How do I see how many rows each thread processed in SQL Server?
Capture the actual execution plan. In the XML each operator has one RunTimeCountersPerThread element per thread with an ActualRows attribute. Graphical plan tools show the same numbers in the operator's properties.