From: Guillaume Smet <guillaume.smet@gmail.com>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Cc: thierry.buffet@fr.nurun.com
Subject: Memory leaks using refcursors
Date: Wed, 17 Jan 2007 19:53:21 +0100
Message-ID: <1d4e0c10701171053t55e60a2epf3e395b5b97101b5@mail.gmail.com> (raw)
Hi all,
We have a problem with an application which uses heavily ref cursors
to fetch results from the database.
We often have the following case:
- BEGIN
- lots of queries using ref cursors (it can run for an hour for
example). We close each result set when we don't use it anymore
- COMMIT
Even if we close the result sets, the memory of the PostgreSQL backend
is not released until the transaction is commited at the end of the
script. This is really a problem for us as PostgreSQL starts swapping
during the transaction.
The code used to manipulate the result set is:
CallableStatement myCallableStatement = myConnexion.prepareCall("{? =
Call cp_TestPostgresStandAlone()}");
myCallableStatement.registerOutParameter(1, Types.OTHER);
myCallableStatement.execute();
ResultSet myResultSet = (ResultSet) myCallableStatement.getObject(1);
/* simple manipulations of the result set */
myResultSet.close();
myCallableStatement.close();
After this two close() calls, the memory used by the cursor should be
released and it's not the case.
The stored proc is something like:
CREATE OR REPLACE FUNCTION cp_TestPostgresStandAlone()
RETURNS refcursor AS
$BODY$
DECLARE stock_cursor refcursor;
BEGIN
OPEN stock_cursor FOR
SELECT COUNT(*) FROM TestPostgresStandAlone;
RETURN stock_cursor;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
AFAICS in the source code, the refcursor of a result set is not closed
when we close the result set and I don't think PostgreSQL closes it by
itself before the final commit.
Is there any way to fix this behaviour?
Thierry (in CC:) wrote a self contained test case to reproduce this
memory leak. We can post it to the list if necessary.
Thanks for your help.
--
Guillaume
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: guillaume.smet@gmail.com, thierry.buffet@fr.nurun.com
Subject: Re: Memory leaks using refcursors
In-Reply-To: <1d4e0c10701171053t55e60a2epf3e395b5b97101b5@mail.gmail.com>
References: <1d4e0c10701171053t55e60a2epf3e395b5b97101b5@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox