pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Duncan Sands <duncan.sands@deepbluecap.com>
To: pgsql-bugs@lists.postgresql.org, Andres Freund <andres@anarazel.de>
Subject: Re: Unlimited memory consumption with long-lived connection
Date: Tue, 21 Feb 2023 16:32:02 +0200
Message-ID: <7484b4bd-a808-ed9e-892c-933f7f24120f@iki.fi> (raw)
In-Reply-To: <a53cacb0-8835-57d6-31e4-4c5ef196de1a@deepbluecap.com>
References: <a53cacb0-8835-57d6-31e4-4c5ef196de1a@deepbluecap.com>

On 21/02/2023 14:57, Duncan Sands wrote:
> If I execute the attached python script against a postgresql 15.2 (Ubuntu
> 15.2-1.pgdg22.10+1) server, with the default configuration (eg shared_buffers =
> 128M), then the server memory usage goes up and up, apparently endlessly.  After
> about 10 minutes (on my laptop) pg_top shows RES memory usage for the back-end
> handling the connection as greater than 1 gigabyte, which seems far too high
> given the server configuration.  The script just performs the same SELECT
> endlessly in a loop.  The memory is released when the script is killed.
> 
> Platform: Ubuntu 22.10; Linux version 5.19.0-31-generic; x86-64.
> 
> PS: The testcase was reduced from a script that kept a connection open for a
> long time in order to LISTEN, and would execute a query using the same
> connection every time there was a notification on the channel.  It consumed ever
> more memory to the point of crashing the postgresql server.  Changing the script
> to perform the query using a new short-lived connection was an effective workaround.

I can reproduce this on my laptop. When I turn 'jit=off', or disable JIT 
inlining with 'jit_inline_above_cost = -1', the leak stops, or at least 
gets small enough that I don't readily see it with 'top' anymore. So it 
seems to be related to LLVM inlining. I'm using LLVM and clang 14.

To track down the leak, I started postgres server with Valgrind, and let 
the script run for 40 iterations with Valgrind. It did report some leaks 
from LLVM inline functions (attached), but I'm not very familiar with 
this code so I'm not sure which ones might be genuine leaks or how to 
fix them.

- Heikki

Attachments:

  valgrind-inline-leak.txt (text/plain, 125.8K) download

view thread (7+ messages)  latest in thread

Message-ID: <7484b4bd-a808-ed9e-892c-933f7f24120f@iki.fi>
Permalink:  ../7484b4bd-a808-ed9e-892c-933f7f24120f@iki.fi/
Also on:    postgresql.org/message-id/7484b4bd-a808-ed9e-892c-933f7f24120f@iki.fi

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: hlinnaka@iki.fi, duncan.sands@deepbluecap.com, andres@anarazel.de
  Subject: Re: Unlimited memory consumption with long-lived connection
  In-Reply-To: <7484b4bd-a808-ed9e-892c-933f7f24120f@iki.fi>
  References: <a53cacb0-8835-57d6-31e4-4c5ef196de1a@deepbluecap.com> <7484b4bd-a808-ed9e-892c-933f7f24120f@iki.fi>

* 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