When PostgreSQL parallel query tuning matters for analytical reads
Parallel query is a planner decision bounded by worker limits. PostgreSQL only splits a plan across background workers when the planner judges that the split is cheaper than a serial run and the configured limits allow it. Tuning matters when large scans, aggregates or joins run slowly on a self-hosted server that has idle CPU during those queries, and the plan shows a single process doing all the work. If the CPU is already saturated by concurrent OLTP traffic, adding workers will mostly move the wait somewhere else.
Before changing any worker setting, run EXPLAIN (ANALYZE, BUFFERS) on the slow query and look for a Gather or Gather Merge node with the Workers Planned and Workers Launched counts. If no Gather node appears, the planner rejected parallelism, often because the query touches a table too small to be worth splitting, uses a function marked as not safe in parallel mode, or sits inside a construct that forces serial execution. If workers are planned but fewer launch than planned, the limits are the constraint. Check max_worker_processes, max_parallel_workers and max_parallel_workers_per_gather together, since the per-query value cannot exceed what the server-wide pools allow.
Many slow analytical reads have a simpler cause. A missing index, stale statistics, a join written in a way that filters late, or a sort that spills to disk will often cost more than parallelism can recover. Confirm the query shape and row estimates first, using the plan's estimated versus actual row counts. Tune parallel settings only once the plan is sound and the remaining time is spent in parallelizable scan or aggregate work. Confirm with your own workload and hardware how much CPU headroom exists at peak, because that determines whether the gain is real for your users.
Which parallel settings to change and when each fits
This table compares the parallel query settings by the situation where each one fits and the risk of raising it. Read each row as a question to answer about your workload before changing the value, and treat the caution column as the reason to test first.
| Setting | When it fits | Risk of raising it |
|---|---|---|
| max_worker_processes | Set first when the host has spare CPU and memory for background workers beyond parallel query, such as replication and autovacuum. | The pool is shared by all background work. A high value can starve autovacuum or logical replication workers when parallel queries run together. |
| max_parallel_workers | Raise when many analytical sessions need parallel workers at the same time and the server has idle cores after the limit is reached. | Concurrent parallel queries compete for CPU and memory, which can slow the short OLTP transactions that share the same cores. |
| max_parallel_workers_per_gather | Raise for a single large scan, join or aggregate that runs alone and has measured speedup in EXPLAIN ANALYZE with more workers. | Each node in a plan can launch this many workers. A high value multiplies across concurrent sessions and can exhaust max_parallel_workers. |
| max_parallel_maintenance_workers | Raise for CREATE INDEX and similar maintenance on large tables during a scheduled window with spare I/O and CPU. | Index builds consume memory and I/O alongside maintenance_work_mem. Running them during peak OLTP hours can raise commit latency. |
| parallel_setup_cost | Lower when the planner keeps medium-sized queries serial even though parallel execution is faster in measured runs. | A low value makes the planner choose parallel plans for small queries, adding worker startup overhead to fast OLTP reads. |
| parallel_tuple_cost | Lower when the planner underestimates the benefit of parallel plans for queries that return many rows to the leader process. | A low value favors parallel plans even where row transfer from workers to the leader dominates, so runtime can get worse. |
| min_parallel_table_scan_size | Lower when large tables below the default threshold should be scanned in parallel for reporting queries. | Lowering it lets smaller tables use parallel scans, which adds overhead for queries that would finish quickly on one process. |
| min_parallel_index_scan_size | Lower when selective parallel index scans on moderately sized indexes are a measured win for analytical access paths. | Parallel index scans on small indexes rarely pay back worker startup cost and can add contention on hot indexes. |
How the planner decides between a serial and a parallel plan
The planner starts when a query is submitted and first checks that max_parallel_workers_per_gather allows any workers at all. It then asks whether the tables or indexes are large enough to be worth splitting. For each candidate, it compares the serial cost with the parallel cost, which adds parallel_setup_cost and parallel_tuple_cost. A parallel plan that wins is then limited by max_worker_processes and max_parallel_workers, so check those limits when a plan you expect to be parallel runs serially.
Decision points the planner checks before choosing a Gather-based plan.
Setting up parallel query on a self-hosted cluster
This sequence moves a cluster from serial plans to verified parallel plans without starving OLTP traffic, by measuring first, checking headroom, changing limits in a fixed order and re-testing latency before calling the change done.
Capture baseline plans for representative queries
Pick the analytical queries that matter most, usually from pg_stat_statements rankings or the reporting schedule, and run each with EXPLAIN (ANALYZE, BUFFERS) on a copy of production-sized data. Record the actual runtime, whether the plan already contains a Gather or Gather Merge node, and the estimated versus actual row counts. Store the plans in version control so later comparisons use the same queries and data. Done when you have a dated file with one serial plan and its runtime for each query in scope.
Confirm CPU and memory headroom
Before raising any worker limit, check the host with your monitoring tools: core count, CPU utilization during the peak OLTP window, load average, and free memory. Parallel workers each consume CPU and, through work_mem, can use memory for every sort or hash node in the plan, so concurrent parallel queries multiply that demand. Note how many cores are idle at peak and whether the instance runs other services. Done when you can state, in writing, how many workers the host can spare at peak without pushing OLTP latency past its target.
Set the worker ceiling before the per-gather limit
Raise max_worker_processes first if the server needs more background workers in total, then max_parallel_workers, which caps parallel workers across all sessions, and only then max_parallel_workers_per_gather, which caps workers for one Gather node. Keep max_parallel_workers at or below max_worker_processes, and leave headroom for other background processes such as logical replication workers. Set max_worker_processes only through postgresql.conf and a restart, while the parallel settings can be reloaded. Done when SHOW reports the new values and the sum of planned parallel workers fits within the host headroom you recorded.
Reload the configuration and confirm the new values
Apply the changes with a configuration reload where the parameter allows it, or a restart after changing max_worker_processes. Confirm each value with SHOW or pg_settings, and check the server log for configuration errors. Verify that the session that will run analytics picks up the setting, since a value changed by a role or database setting can differ from the server default. Done when pg_settings reports the intended values for the analytical role and the server log shows no startup or reload errors.
Verify plans contain Gather nodes
Rerun the baseline queries with EXPLAIN (ANALYZE, BUFFERS) in the same session settings. Look for Gather or Gather Merge nodes with the Workers Planned and Workers Launched lines, and compare runtime with the baseline. If a plan is still serial, check the table size against min_parallel_table_scan_size, whether the query uses parallel-unsafe functions, and whether the planner has enough row estimates to choose parallel paths. Done when each target query either shows a Gather node with launched workers and a measured improvement, or has a recorded reason it stays serial.
Check parallel index builds separately
If the work includes index creation, set max_parallel_maintenance_workers for the session that runs CREATE INDEX or REINDEX, rather than changing the server default. Check the build with the progress view for CREATE INDEX and confirm the number of workers in the log or progress output. Size maintenance_work_mem with the planned workers in mind, since it applies per worker for parallel builds. Done when a test build on a copy shows the expected worker count and the index is usable by the planner.
Re-test OLTP latency under mixed load
Run your transactional workload, ideally a custom pgbench script that mirrors production, alone and then alongside the parallel analytical queries at the times they will run. Compare latency percentiles and throughput with the pre-change baseline, and watch CPU, I/O wait and lock waits on the host. Keep the change if OLTP latency stays within the target you set in step two and analytics improve; otherwise lower the per-gather limit and repeat. Done when you have a before and after latency record under the same mixed load and a documented decision on the final values.
Why analytical queries still run serially
A serial plan usually has a specific, checkable cause. Before changing max_parallel_workers_per_gather, run EXPLAIN (ANALYZE, BUFFERS) on the slow query and look for Gather or Gather Merge nodes. If they are absent, the planner chose a serial path, and the reason is almost always one of the causes below. The first is table size. Parallel scans only start when the planner estimates enough pages to justify the worker startup cost, governed by min_parallel_table_scan_size. A small table, or a large table whose filter leaves few rows, will stay serial by design. Confirm this by comparing the scanned relation's size with the threshold and by checking whether the estimated row count is small. The second is parallel-unsafe functions or expressions. A user-defined function marked PARALLEL UNSAFE (the default for functions you create) blocks parallelism for any plan node that calls it, and the plan shows no Gather above that part of the query. Check pg_proc.proparallel for each function in the WHERE clause, select list or join condition, and mark functions PARALLEL SAFE only after reviewing that they do not write data or depend on session state.
The third cause is queries whose shape cannot be parallelized, such as some cursor uses, data-modifying statements in certain positions, and operations that require a single-process result. The planner will not add a Gather where the query cannot support it, so rewrite the query only if the plan confirms the barrier. The fourth is cost estimates that favor serial execution. When the planner estimates few rows, or cost inputs such as parallel_setup_cost and parallel_tuple_cost make parallel overhead look larger than the gain, it keeps the serial plan. Compare estimated and actual row counts on the nodes below the would-be Gather. A large gap usually points to the fifth cause, stale statistics, which is fixed by running ANALYZE on the table and reviewing autovacuum behavior. The sixth cause is an exhausted worker pool. The plan may show Workers Planned lower than Workers Launched or fewer than requested, which means max_parallel_workers, max_worker_processes or max_parallel_workers_per_gather capped the count. Ask your team how many analytical sessions run at once, since each one competes for the same pool. Settings such as max_parallel_workers are server-wide, so confirm the current values with SHOW before deciding.
How parallel workers affect concurrent OLTP traffic
Parallel workers take CPU, memory, connections and disk bandwidth from the same server that handles short transactions. The cards below cover the risks that appear when analytical parallelism runs next to OLTP traffic, and the signals to check before raising any parallel limit.
CPU contention with short transactions
Each parallel query gather starts up to the planned number of workers, and those workers compete with OLTP backends for CPU cores. A short transaction that normally finishes in milliseconds can wait for a free core when several large scans run at once. Check run queue length and CPU steal during the analytical window, and compare p95 or p99 latency for OLTP statements with and without the reports running. Set max_parallel_workers below the total core count so some capacity stays free for transactions.
Memory multiplied by workers
Each parallel worker can use its own work_mem for sorts and hashes, and a plan with several hash nodes can use more than one allocation per worker. The total can grow far beyond what the server has free, which pushes the host toward swapping or the OOM killer. Before raising max_parallel_workers_per_gather, estimate peak memory as concurrent queries times workers times the memory per operation, and check that figure against available RAM. Lower work_mem for roles that run reports.
Connection and pool pressure
Parallel workers are background processes counted against max_worker_processes and max_parallel_workers, not against max_connections. Yet a single report also holds a client connection, and a pooler such as PgBouncer may hold a server connection for the duration of the query. When analytical sessions queue behind each other, OLTP clients see timeouts at the pool even though the database has idle CPU. Confirm the pool mode and size for reporting users separately from application users.
I/O saturation during scans
Parallel sequential scans read large portions of a table at once, which can fill the storage queue and slow every read and write that OLTP traffic needs. The effect is strongest on shared storage or on volumes with modest IOPS. Watch disk utilization, read and write latency, and the share of time backends spend waiting on I/O during the report window. Running large scans against a replica, where the environment allows it, moves this load away from the primary.
Lock and replication effects
Parallel index builds with CREATE INDEX take a lock that blocks writes to the table, and parallel workers for the build hold maintenance_work_mem in addition to the leader. Long analytical transactions also hold snapshots that stop vacuum from removing dead rows, which increases table bloat. On a primary with synchronous replication, heavy write bursts can delay commits that wait for standbys. Schedule builds in maintenance windows and check pg_stat_activity for long-running snapshots.
Monitoring signals to watch
Measure before and after each change to a parallel limit, not only the report run time. Useful signals include the number of planned versus launched workers in EXPLAIN ANALYZE, OLTP latency percentiles, CPU and I/O utilization, buffer cache hit ratio, temporary file use, and the age of the oldest transaction. Pair these with a repeatable load test that includes both report and transaction traffic. Confirm which of these views your monitoring stack already collects before you rely on them.
Questions teams ask before hiring help with parallel query tuning
What drives the cost of a parallel query tuning engagement?
The main driver is how many slow analytical queries are in scope and how varied their plans are. Each query needs its plan read, its bottleneck identified and a change tested, so a backlog of ten similar reports costs less than ten unrelated ones. Other drivers are the number of PostgreSQL clusters involved, whether the work includes a hardware or Linux review, how much benchmarking is needed to prove that OLTP latency holds, and how many test cycles the team agrees to. Cost is paid mainly as skilled engineering time, plus any test environment you need. Ask a quote to list the queries in scope, the environments tested, the number of rounds of change and retest, and whether the write-up of settings and rollback steps is included.
How long does parallel query tuning usually take?
Duration depends on the number of queries, how many are blocked by something other than worker settings, and how easily you can test changes outside peak hours. A focused review of a small set of reports moves faster than a review that spans many workloads, because each query type needs its own plan analysis and its own before-and-after measurement. Environment matters too: a production-like test copy with realistic data volumes takes longer to prepare than a shared staging server with a few gigabytes. Ask for a timeline built from the agreed query list, the test environment and the number of change windows, and ask which steps depend on your access.
What must our team provide before a tuning engagement starts?
The work goes faster when the team supplies the evidence a tuner would otherwise have to collect. Typically that means:
- The slow queries, ideally with their text, parameters and how often they run
EXPLAIN (ANALYZE, BUFFERS)output from representative runs, plus plans captured under concurrent load if that is where the problem appears- A sample of the workload at busy and quiet times, and the current values of
max_parallel_workers_per_gather,max_parallel_workers,max_worker_processesandmax_parallel_maintenance_workers - Hardware, storage and PostgreSQL version details, and the OLTP latency targets that must hold
- Access windows for testing, plus a named owner who can approve changes
Confirm with your team which of these exist and how long they take to pull from production.
Can our own team tune parallel query settings using the documentation?
Yes, many teams can handle simple cases with the PostgreSQL documentation, especially if they already read execution plans well. The parameters are documented, and a single query can often be tested in a session with a changed setting. The harder part is what the documentation does not do for you: deciding which queries are worth parallelizing, separating a planner estimate problem from a worker limit, and checking that a change does not take workers away from OLTP traffic across the whole day. A useful test is whether your team can explain why a given plan stays serial, measure the effect of a change at the same concurrency as production, and roll the change back. If not, an outside review can shorten that learning curve.
How do we avoid hurting OLTP latency while tuning for analytics?
Parallel workers are drawn from a shared pool, so an analytical query that starts many workers can leave transactional queries waiting for CPU and I/O. Protect latency by testing under realistic concurrency, not on an idle server. Raise worker limits in small steps, measure p95 or p99 latency for OLTP statements during the test, and keep max_parallel_workers and max_worker_processes sized to the cores you can spare. Separate analytical work where possible, by running reports on a read replica or during quieter windows, and set per-role or per-session limits so reporting jobs cannot take the whole pool. Parallel index builds deserve the same care, because max_parallel_maintenance_workers changes how much I/O a build generates during business hours.
How is a fixed-scope tuning engagement agreed?
DeployOpen works on most engagements under a fixed scope. Before work starts, the scope, deliverables and timeline are agreed in writing. The scope names the queries, clusters and environments included, the changes DeployOpen may test, the reports and runbooks delivered, and the retest that confirms each change. Anything outside that list, such as a schema redesign or a new replica, is quoted as a separate change. A quote follows from the written scope, so the more precisely you list queries, environments and acceptance criteria, the more precise the quote. DeployOpen does not publish a price list.
Does tuning change a production database, and who approves it?
Tuning should not change production without approval. Usually the work starts with analysis and changes tested on a copy that resembles production, then moves to a change window agreed with your operations team. The written scope should state who approves each change, how changes are applied and recorded, and what the rollback path is. Parallel query settings are often reloaded without a restart, but some related settings need one, so confirm that with the PostgreSQL version you run. Ask for each change to be documented with its before-and-after plan and measurements.
What happens after the tuning work is delivered?
Plans change as data grows, as indexes are added and as PostgreSQL is upgraded, so a set of settings can drift out of its tested range. Plan for the team to keep the query baseline, rerun the key reports after data volume changes and review settings before a major upgrade. Ongoing checks can be covered by a retainer if you want continuous testing rather than a one-time review. Ask the quote to state what handover material is included and who owns the runbook afterward.
How DeployOpen scopes and delivers parallel query tuning
DeployOpen approaches PostgreSQL parallel query tuning as a written, fixed-scope engagement inside infrastructure you control. We start from the queries and plans that are slow, change one setting at a time, and verify the effect on concurrent transactional traffic before handing anything over.
How we scope
- Agree in writing which analytical queries, reports and maintenance jobs are in scope for parallel tuning.
- Record current PostgreSQL version, hardware cores, memory, and the OLTP load that parallel workers must not starve.
- Confirm which settings may change, such as max_parallel_workers_per_gather and max_worker_processes, and which need approval.
- Define acceptance measures with your team, including target query timings and latency limits for concurrent transactions.
How we build
- Capture baseline EXPLAIN ANALYZE output for target queries to see why plans stay serial or use too few workers.
- Test candidate limits in a staging copy of your data, changing one parameter per run and recording the results.
- Review parallel index build settings such as maintenance_work_mem against memory headroom on production hosts.
- Benchmark mixed workloads with your own scripts so transactional latency is measured alongside analytical runtime.
How we hand over
- Deliver the final configuration as files your team can review, with each changed setting and its reason recorded.
- Document the before and after plans, timings and concurrency results for every query group that was tuned.
- Provide a runbook listing which queries depend on parallel execution and what to check after a PostgreSQL upgrade.
- Walk your database and platform engineers through the findings so they can repeat the tests themselves.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer if workloads or data volumes change.
- Re-run the target query set after each PostgreSQL minor or major upgrade to confirm plans still parallelize as expected.
- Review new analytical workloads against the agreed limits before they are added to shared production hosts.
- Quote any follow-up work from a written scope, so changes to tuning targets are agreed before they start.

