PG Bug reporting form <noreply@postgresql.org> writes:
> Aggregate queries on partitioned tables can cause out of memory error.
This is resolved in PG v13 and later. In older versions, it's
advisable to do an explicit ANALYZE on a large table, so that the
planner knows that the number of groups is large and will avoid
trying to do a hash aggregation.
(I don't think it's terribly specific to partitioned tables,
for what that's worth, except that stats for a partitioned
table might be more likely to be out-of-date.)
regards, tom lane