"Anita Lederer" <anita.lederer@googlemail.com> writes:
> i have a statement which ends with
> ERROR: out of memory
> DETAIL: Failed on request of size 639.
Do you have work_mem set to a large value? Your query plan contains
several sorts so would potentially try to use several times work_mem
... if that's more than the kernel will allow one process to have,
you would get a failure like this.
The other theory that comes to mind is that you've discovered an
intraquery memory-leak bug, but there's not nearly enough information
here to find it if so.
The out-of-memory error should result in dumping a list of memory
context statistics into the postmaster's log file --- if you can post
that information it would be helpful.
regards, tom lane