The following bug has been logged online:
Bug reference: 5608
Logged by: Itagaki Takahiro
Email address: itagaki.takahiro@gmail.com
PostgreSQL version: 9.0beta4
Operating system: Windows 7 (32bit)
Description: array_agg() consumes too much memory
Details:
I encountered "out of memory" error in large
GROUP BY query with array_agg(). The server log
was filled by the following messages:
accumArrayResult: 8192 total in 1 blocks; 7800 free (0 chunks); 392
used
Should we choose smaller size of initial memory in accumArrayResult()?
It allocates ALLOCSET_DEFAULT_INITSIZE (=8kB) now,
but only 10% of the area was used in my case.
Note that work_mem is not considered in the case;
array_agg() allocates 8kB * (number of groups).