Unexpected memory usage for repeated inserts within plpgsql function - Mailing list pgsql-hackers

From happy times
Subject Unexpected memory usage for repeated inserts within plpgsql function
Date
Msg-id tencent_5C738ECA65BAD6861AA43E8F@qq.com
Whole thread Raw
Responses Re: Unexpected memory usage for repeated inserts within plpgsql function  (Dilip Kumar <dilipbalaut@gmail.com>)
List pgsql-hackers
Hi Hackers,

I have been seeing memory usage increasing for a simple plpgsql function. Could you please take a look and check is it a bug?

The function definition is:

create function f() returns int as
$$DECLARE count int;
BEGIN
    count := 1;
    LOOP
        count := count + 1;

        begin

            EXECUTE 'insert into test values(10)';

            IF count > 1000000 THEN
                EXIT;
            END IF;
        exception when others then

        end;
    END LOOP;

END$$
LANGUAGE plpgsql;

When I ran this function by "select f()", from top command, I could see memory usage (Resident memory) kept on increasing:


Then I used gdb to suspend the process each time insert was actually executed, and issued "   (gdb) p MemoryContextStats(TopMemoryContext) ". From the server log, I saw only "SPI Proc" part of all the memory contexts was increasing:


My question: Is this problem as-designed?

Thank you for your time!!
Guangzhou

Attachment

pgsql-hackers by date:

Previous
From: Kyotaro HORIGUCHI
Date:
Subject: Re: [BUG] pg_basebackup from disconnected standby fails
Next
From: Jim Mlodgenski
Date:
Subject: Re: PoC: Make it possible to disallow WHERE-less UPDATE and DELETE