> Huh, I was overthinking the problem. xml_out has a memory leak :-(
>
> More than one in fact: a large leak (equal to size of output) in
> the executor context (hence query lifespan) and a small one in
> LibxmlContext (hence transaction lifespan).
>
> Try the patch here:
> http://archives.postgresql.org/pgsql-committers/2008-09/msg00159.php
I've applied this patch now to our staging and production environments,
and Postgres performed quite well after testing very large result sets
that were previously failing with out of memory errors... so the patch is
successful for this problem I was having. I didn't see any significant
increase in memory over the course of the query execution, in fact.
Thanks!
-- m@