Re: Memory exhausted (leak?)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: apb18(at)cornell(dot)edu
Cc: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Memory exhausted (leak?)
Date: 2004-09-10 03:19:27
Message-ID: 13425.1094786367@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Aaron Birkland <birkie(at)gmail(dot)com> writes:
> - why did the amount of memory used for the hash join exceed sort_mem?
> Is sort_mem merely a guideline for planning and not an enforced hard
> limit?

Yup. The deal is that hash join has to decide in advance on how many
"batches" it wants to have (because it will divide up the hash key range
into that many sub-joins). It sets the number of batches as
(estimated total table size) / sort_mem
It will then soldier on trying to stuff one batch's worth of tuples into
memory, no matter how much larger or smaller than sort_mem that turns
out to be.

This doesn't usually present that much of a problem in practice, because
with customary values of sort_mem there is a lot of margin for error.
I am wondering if maybe you are using an optimistically large sort_mem
setting?

> - why wasn't the memory cleared after the transaction finished
> (failed)? The process was still 2GB large. Does memory used for
> sorts just stay around, possibly re-used for other sorts or hashes but
> never de-allocated?

That depends on the details of your malloc package and your kernel, but
on many Unixen a process never really shrinks.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dann Corbit 2004-09-10 03:19:28 Re: So, would it make sense to do something like a CRC on
Previous Message Bruce Momjian 2004-09-10 03:05:18 Re: So, would it make sense to do something like a CRC on