Re: Memory leak with CALL to Procedure with COMMIT.

From: "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Prabhat Sahu <prabhat(dot)sahu(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: Memory leak with CALL to Procedure with COMMIT.
Date: 2018-08-01 17:42:29
Message-ID: 6D2BDA4B-9D54-45DC-8F15-EC376611DFD1@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> On Jul 23, 2018, at 3:06 AM, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Mon, Jul 23, 2018 at 12:19:12PM +0530, Prabhat Sahu wrote:
>> While testing with PG procedure, I found a memory leak on HEAD, with below
>> steps:
>>
>> postgres=# CREATE OR REPLACE PROCEDURE proc1(v1 INOUT INT)
>> AS $$
>> BEGIN
>> commit;
>> END; $$ LANGUAGE plpgsql;
>> CREATE PROCEDURE
>>
>> postgres=# call proc1(10);
>> WARNING: Snapshot reference leak: Snapshot 0x23678e8 still referenced
>> v1
>> ----
>> 10
>> (1 row)
>
> I can reproduce this issue on HEAD and v11, so an open item is added.
> Peter, could you look at it?

I tested and was able to reproduce this on head. I also tried a few other other
and was able to reproduce it when the procedure contained a few read-only
statements prior to commit, where the argument passed in was designated "INOUT."

Scenarios 1 & 2 show the leak whereas 3 & 4 do not.

/** Scenario 1: Original scenario */
CREATE OR REPLACE PROCEDURE proc1(v1 INOUT INT)
AS $$
BEGIN
commit;
END; $$ LANGUAGE plpgsql;

CALL proc1(10);

WARNING: Snapshot reference leak: Snapshot 0x7f9519826d18 still referenced
CONTEXT: PL/pgSQL function proc1(integer) line 3 at COMMIT
v1
----
10
(1 row)

/** Scenario 2: call "perform" prior to the commit */
CREATE OR REPLACE PROCEDURE proc2(v1 INOUT INT)
AS $$
BEGIN
PERFORM v1;
COMMIT;
END; $$ LANGUAGE plpgsql;

CALL proc2(10);
WARNING: Snapshot reference leak: Snapshot 0x7f9519826d18 still referenced
CONTEXT: PL/pgSQL function proc2(integer) line 4 at COMMIT
v1
----
10
(1 row)

/** Scenario 3: argument is only IN */
CREATE OR REPLACE PROCEDURE proc3(v1 IN INT)
AS $$
BEGIN
PERFORM v1;
COMMIT;
END; $$ LANGUAGE plpgsql;

CALL proc3(10);
CALL

/** Scenario 4: Same as #2 but with a ROLLBACK */
CREATE OR REPLACE PROCEDURE proc4(v1 INOUT INT)
AS $$
BEGIN
PERFORM v1;
ROLLBACK;
END; $$ LANGUAGE plpgsql;

CALL proc4(10);
CALL

Jonathan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-08-01 17:43:24 Re: Online enabling of checksums
Previous Message Joshua D. Drake 2018-08-01 17:34:55 Re: Online enabling of checksums