Andrew Dunstan <andrew@dunslane.net> writes:
> I'm really perplexed as to why this fairly simple query should cause an
> out of memory error:
> select loid, max(pageno) from ldata group by loid order by 2 desc
> limit 10;
Looks like the group by/aggregate step is eating lots of memory:
> AggContext: 864018432 total in 127 blocks; 3400 free (110
> chunks); 864015032 used
> TupleHashTable: 619175960 total in 95 blocks; 821528 free
> (331 chunks); 618354432 used
A guess is that there are a huge number of distinct values of "loid" but
the planner fails to realize that and tries to use a hash aggregation.
Could we see EXPLAIN output for this query?
regards, tom lane