Re: BUG #14078: Excessive memory growth during nested loop in select - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #14078: Excessive memory growth during nested loop in select
Date
Msg-id 5559.1460495739@sss.pgh.pa.us
Whole thread Raw
In response to BUG #14078: Excessive memory growth during nested loop in select  (psuderevsky@gmail.com)
List pgsql-bugs
psuderevsky@gmail.com writes:
> [ query producing a 46-million-row join result ]

> Observing amount of memory consumed by psql process with pmap utility...
> So about 8Gb of linux virtual memory has been allocated for join of two
> tables with sizes of 11MB.
> The question is why so high amount of virtual memory is consumed, isn't it
> a memory leak.

No, it's just a very large query result.  psql collects the entire query
result into memory before printing any of it, so that it can format the
result nicely.  If you're dealing with query results large enough for that
to be a problem, you could consider using psql's FETCH_COUNT variable to
make it fetch and format a smaller number of rows at a time; which would
trade off the niceness of the formatting for less memory usage.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Magnus Hagander
Date:
Subject: Repeated requests for feedback in logical standby
Next
From: Christoph Berg
Date:
Subject: Bus error in pg_logical_slot_get_changes (9.4.7, sparc)