possibility to define only local cursors

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: possibility to define only local cursors
Date: 2023-11-30 05:45:23
Message-ID: CAFj8pRC-+X4QPxGF3ReA12arY-x4aHYRK=taha9P+05FziJXAQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

one my customer migrated a pretty large application from Oracle, and when
did performance tests, he found very high memory usage related probably to
unclosed cursors. The overhead is significantly bigger than on Oracle
(probably Oracle closes cursors after leaving cursor's variable scope, I
don't know. Maybe it just uses a different pattern with shorter
transactions on Oracle). He cannot use FOR cycle, because he needs to hold
code in form that allows automatic translation from PL/SQL to PL/pgSQL for
some years (some years he will support both platforms).

DECLARE qNAJUPOSPL refcursor;
BEGIN
OPEN qNAJUPOSPL FOR EXECUTE mSqNAJUPOSPL;
LOOP
FETCH qNAJUPOSPL INTO mID_NAJVUPOSPL , mID_NAJDATSPLT , mID_PREDPIS;
EXIT WHEN NOT FOUND; /* apply on qNAJUPOSPL */
END LOOP;
END;

Because plpgsql and postgres can be referenced just by name then it is not
possible to use some reference counters and close cursors when the
reference number is zero. Can we introduce some modifier that forces
closing the unclosed cursor before the related scope is left?

Some like `DECLATE curvar refcursor LOCAL`

Another way to solve this issue is just warning when the number of opened
cursors crosses some limit. Later this warning can be disabled, increased
or solved. But investigation of related memory issues can be easy then.

Comments, notes?

Regards

Pavel

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2023-11-30 05:47:57 Re: possibility to define only local cursors
Previous Message Andrei Lepikhov 2023-11-30 04:59:32 Re: Custom explain options