Thread: Memory Leaks in plpgsql in 7.0.2

Memory Leaks in plpgsql in 7.0.2

From
"Chris Knight"
Date:
Howdy,

I've sent the following to Jan Weick, but haven't heard a reply. Thought I'd
send it to the list to see if others are having the same problem, and to see
if any Postgres developer reading this list will take ownership for this
problem:

I've found I've had to do a lot of plpgsql rewriting to avoid memory
exhaustion due to calling the functions multiple times in the one session.
Specifically, I've found that huge memory leaks occur when variables are
re-assigned based on a previous value (ie var := var + 1), and also when
strings are concatenated. Worse still is when you use the concatenation to
append to an existing variable.

Careful coding (plus extra memory and swap space!) has allowed us to still
be using Postgres, but it is a bit worrying that plpgsql can't even do
i:=i+1 reliably. It would be nice to know if this could be addressed prior
to the 7.1 release.


Regards,
Chris Knight
Systems Administrator
AIMS Independent Computer Professionals
Tel: +61 3 6334 6664  Fax: +61 3 6331 7032  Mob: +61 419 528 795
Web: http://www.aims.com.au



Re: Memory Leaks in plpgsql in 7.0.2

From
Tom Lane
Date:
"Chris Knight" <chris@aims.com.au> writes:
> I've found I've had to do a lot of plpgsql rewriting to avoid memory
> exhaustion due to calling the functions multiple times in the one session.

I believe this has probably been fixed already by the memory context
changes I've been working on --- I think that space allocated in PL
functions will now be reclaimed once per tuple not once per query.
Would you mind trying your problem cases with a current snapshot?

            regards, tom lane