Memory leaks using refcursors

Поиск
Список
Период
Сортировка
От Guillaume Smet
Тема Memory leaks using refcursors
Дата
Msg-id 1d4e0c10701171053t55e60a2epf3e395b5b97101b5@mail.gmail.com
обсуждение исходный текст
Ответы Re: Memory leaks using refcursors
Список pgsql-jdbc
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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Csaba Nagy
Дата:
Сообщение: Re: Strange error using postgres 8.2 + JDBC 8.2 driver
Следующее
От: "Guillaume Smet"
Дата:
Сообщение: Re: Memory leaks using refcursors