Configuration parameter

enable_partitionwise_aggregate — PostgreSQL configuration parameter

Category Query Planning Default off

Enables or disables the query planner’s use of partitionwise grouping or aggregation, which allows grouping or aggregation on partitioned tables to be performed separately for each partition.

At a glance

Property Value
Parameter enable_partitionwise_aggregate
Category Query Planning
Default off
Value type boolean (on/off)
Change scope Per-session (SET)
Available in PostgreSQL 12, 13, 14, 15, 16, 17, 18, 19 (added in 12)

What it does

Enables or disables the query planner’s use of partitionwise grouping or aggregation, which allows grouping or aggregation on partitioned tables to be performed separately for each partition. If the GROUP BY clause does not include the partition keys, only partial aggregation can be performed on a per-partition basis, and finalization must be performed later. With this setting enabled, the number of nodes whose memory usage is restricted by work_mem appearing in the final plan can increase linearly according to the number of partitions being scanned. This can result in a large increase in overall memory consumption during the execution of the query. Query planning also becomes significantly more expensive in terms of memory and CPU. The default value is off.

(Description quoted from the official PostgreSQL documentation.)

How to apply a change

Can be set per session with SET, per role/database with ALTER ROLE/DATABASE ... SET, or globally in postgresql.conf.

Inspect the current value and source with SHOW enable_partitionwise_aggregate; or SELECT name, setting, unit, context, source FROM pg_settings WHERE name = 'enable_partitionwise_aggregate';.

Tuning guidance

This is a diagnostic switch, not a production tuning knob. Turn it off briefly (per session) to confirm why the planner avoids or prefers a plan, then leave it on. Forcing it off in production masks bad estimates instead of fixing them — fix statistics, costs or indexes instead.

Reference

PostgreSQL documentation — enable_partitionwise_aggregate.

Keep going

Related & next steps

Concepts on this page

Was this helpful?

← All configuration parameters