pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: ben@lantern.is
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16112: large, unexpected memory consumption
Date: Wed, 13 Nov 2019 15:50:04 +0100
Message-ID: <20191113145004.opxx4vuajyoadbcq@development> (raw)
In-Reply-To: <16112-4448bbf55a404189@postgresql.org>
References: <16112-4448bbf55a404189@postgresql.org>

On Wed, Nov 13, 2019 at 12:22:07PM +0000, PG Bug reporting form wrote:
>The following bug has been logged on the website:
>
>Bug reference:      16112
>Logged by:          Ben Cornett
>Email address:      ben@lantern.is
>PostgreSQL version: 12.0
>Operating system:   linux 2.6.32
>Description:
>
>Creation of table t1 in the query below causes the server process to consume
>close to 1GB of memory.  The amount of memory consumed is proportional to
>the value passed to generate_series in the first query.
>
>CREATE temp TABLE t0 AS
>SELECT
>        i,
>        ARRAY[1,2,3] a
>FROM GENERATE_SERIES(1, 12000000) i
>;
>
>CREATE TEMP TABLE t1 AS
>SELECT
>        i,
>        x
>FROM t0, UNNEST(a) x;
>
>I observed the same behavior in other test queries that included implicit
>lateral joins.
>

Yeah, I can reproduce this pretty easily. It seems like a memory leak in
ExecMakeTableFunctionResult. a9c35cf85ca reworked FunctionCallInfo to be
variable-length, but it gets allocated in ExecutorState context directly
and so until the end of the query.

The attached trivial patch fixes that by adding a pfree() at the end of
the function. I wonder if we have the same issue elsewhere ...


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

memleak-a9c35cf85ca.patch (text/plain, 362B) download diff --git a/src/backend/executor/execSRF.c b/src/backend/executor/execSRF.c index c8a3efc365..da19bbfc66 100644 --- a/src/backend/executor/execSRF.c +++ b/src/backend/executor/execSRF.c @@ -412,6 +412,8 @@ no_function_result: MemoryContextSwitchTo(callerContext); + pfree(fcinfo); + /* All done, pass back the tuplestore */ return rsinfo.setResult; }

view thread (16+ messages)  latest in thread

Message-ID: <20191113145004.opxx4vuajyoadbcq@development>
Permalink:  ../20191113145004.opxx4vuajyoadbcq@development/
Also on:    postgresql.org/message-id/20191113145004.opxx4vuajyoadbcq@development

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, ben@lantern.is, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16112: large, unexpected memory consumption
  In-Reply-To: <20191113145004.opxx4vuajyoadbcq@development>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox