AdvancedPerformance & Indexes

Parallel query configuration

The query

SQL
-- Enable parallel query (check postgresql.conf)
SET max_parallel_workers_per_gather = 4;
SET parallel_tuple_cost = 0.1;
SET parallel_setup_cost = 100;

-- Force parallel for testing
SET force_parallel_mode = on;

-- Example: parallel aggregation
EXPLAIN (ANALYZE)
SELECT dept_id, AVG(salary)
FROM employees
GROUP BY dept_id;
-- Should show "Gather" node in plan if parallel

-- Reset
RESET force_parallel_mode;
Tested against PostgreSQL 16

Note

Parallel queries use multiple CPU cores. PostgreSQL decides based on table size and costs. Tuning thresholds can help.

Tables referenced