BUG #3418: Memory leak with sql EXCEPTION?

From: "Viatcheslav" <vka(at)ipcb(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3418: Memory leak with sql EXCEPTION?
Date: 2007-06-29 19:14:29
Message-ID: 200706291914.l5TJETf5086437@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3418
Logged by: Viatcheslav
Email address: vka(at)ipcb(dot)net
PostgreSQL version: 8.2.4
Operating system: RedHat Linux kernel 2.6.9-34.EL
Description: Memory leak with sql EXCEPTION?
Details:

On our system we came across the following issue:

/---------------------------------------------------/
create table dummy(
id integer primary key,
value varchar(10)
);

CREATE OR REPLACE FUNCTION "public"."test" (fi integer) RETURNS
"pg_catalog"."void" AS
$body$
declare
vi integer;
idx integer := 0;
begin

while idx < fi loop
idx := idx + 1;
begin
insert into dummy values (idx, idx::varchar);
exception
when others then
raise exception '% %', idx, 'stop';
end;
end loop;
end;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY DEFINER;

select test(10000000);

/---------------------------------------------------/

We've been watching CPU and memory usage during the execution of the
'select' with and without exception trap of 'insert'. While in the second
case memory usage kept being relatively low and stayed constant at the level
of approx 2.9Mb across the execution time, in the first case it gradually
raised with step of approx 6Mb up to somewhat 140Mb in the end.
With more complicated PL/PgSQL code (with the same structure: begin -
exception - end block in the main function, some complex function (without
exceptions inside them) doing actual job were called from there) we've run
out of virtual memory (> 1Gb) already with 30000 cycles loop and the process
got killed by operating system. Again, everything worked just fine with
negligible memory consumption without exceptions.
We are aware of additional costs of exceptions yet this one appears to be a
memory leak.

My apologies for poor-styled report in advance for this is my first one.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2007-06-29 20:12:09 Re: BUG #3418: Memory leak with sql EXCEPTION?
Previous Message David Boesch 2007-06-29 12:43:36 Re: BUG #3417: Foreign key constraint violation occurs unexpectedly