execution of prepared statements leaks memory

From: Dmitry Karasik <dmitry(at)karasik(dot)eu(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: execution of prepared statements leaks memory
Date: 2005-09-28 12:36:04
Message-ID: 847jd1s72j.fsf@tetsuo.karasik.eu.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi,

I'm not sure whether I've stumbled over a bug or a feature, so I'm
curious if someone might explain that. The statement below declares
a stored procedure:

CREATE LANGUAGE PLPGSQL;
DROP TABLE memleak_test;
CREATE TABLE memleak_test (id serial);

CREATE OR REPLACE FUNCTION memleak(INTEGER) RETURNS INTEGER AS $$
DECLARE
c ALIAS FOR $1;
i INTEGER;
BEGIN
EXECUTE 'PREPARE leak AS INSERT into memleak_test values (1);';
FOR i IN 1..c LOOP
EXECUTE 'EXECUTE leak;';
END LOOP;
EXECUTE 'DEALLOCATE leak;';
RETURN 0;
END;
$$ LANGUAGE PLPGSQL;

and that procedure, if being called repeatedly, say, as
'SELECT memleak(30000)' causes postmaster to eat memory rather noticeably,
one my machine, for example, first call to memleak(30000) eats 100M, second
50M, and the subsequent calls leak 1-3M per call.

The same leak occurs when I've tried the same code writte on plperl, so
it doesn't seem that the effect is related to plpgsql.

--
Sincerely,
Dmitry Karasik

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2005-09-28 12:43:22 Re: Making pgxs builds work with a relocated installation
Previous Message Qingqing Zhou 2005-09-28 09:25:49 Re: Database file compatability