Re: Memory for BYTEA returned by C function is not released until connection is dropped

From: John Leiseboer <jleiseboer(at)bigpond(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Memory for BYTEA returned by C function is not released until connection is dropped
Date: 2015-09-21 06:08:44
Message-ID: 1EC7FC2A429FF940B43E21AC8D1EECD057F53D66@qbrick.homeip.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us] writes:
> But at any rate, bottom line is that your problem is client-side not server-side, and no amount of fooling with the function innards will change it.

I wish it were. While monitoring memory on Linux and Windows machines I see that psql memory usage hardly changes, but PostgreSQL server memory usage increases steadily until the query stops. PostgreSQL server memory usage stays high until after the client drops the connection. This is definitely a case of the server holding onto memory until the client drops the connection.

In other case, when I let the query continue until memory is exhausted, the PostgreSQL server crashes with "out of memory" error, not the client.

When does the PostgreSQL server call pfree() after a C function has returned to the caller? All I've found in books and Google searches is:

"What makes palloc() special is that it allocates the memory in the current context and the whole memory is freed in one go when the context is destroyed."

What "context"? The connection? The transaction? A SQL statement? The function call?

John

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Etienne Champetier 2015-09-21 07:31:29 looking for old rpm
Previous Message Tom Lane 2015-09-21 03:58:00 Re: Memory for BYTEA returned by C function is not released until connection is dropped