Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

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: 28 Sep 2005 14:36:04 +0200
  • Message-id: <847jd1s72j(dot)fsf(at)tetsuo(dot)karasik(dot)eu(dot)org>

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




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group