pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Reduce memory consumption for multi-statement query strings.
Date: Wed, 10 Jul 2019 18:32:50 +0000
Message-ID: <E1hlHOc-0001UM-0K@gemulon.postgresql.org> (raw)

Reduce memory consumption for multi-statement query strings.

Previously, exec_simple_query always ran parse analysis, rewrite, and
planning in MessageContext, allowing all the data generated thereby
to persist until the end of processing of the whole query string.
That's fine for single-command strings, but if a client sends many
commands in a single simple-Query message, this strategy could result
in annoying memory bloat, as complained of by Andreas Seltenreich.

To fix, create a child context to do this work in, and reclaim it
after each command.  But we only do so for parsetrees that are not
last in their query string.  That avoids adding any memory management
overhead for the typical case of a single-command string.  Memory
allocated for the last parsetree would be freed immediately after
finishing the command string anyway.

Similarly, adjust extension.c's execute_sql_string() to reclaim memory
after each command.  In that usage, multi-command strings are the norm,
so it's a bit surprising that no one has yet complained of bloat ---
especially since the bloat extended to whatever data ProcessUtility
execution might leak.

Amit Langote, reviewed by Julien Rouhaud

Discussion: https://postgr.es/m/87ftp6l2qr.fsf@credativ.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b5810de3f4eb0e7b242d31db93a46957d56ea8b4

Modified Files
--------------
src/backend/commands/extension.c | 16 ++++++++++++++++
src/backend/tcop/postgres.c      | 30 +++++++++++++++++++++++++-----
2 files changed, 41 insertions(+), 5 deletions(-)



Message-ID: <E1hlHOc-0001UM-0K@gemulon.postgresql.org>
Permalink:  ../E1hlHOc-0001UM-0K@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hlHOc-0001UM-0K@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Reduce memory consumption for multi-statement query strings.
  In-Reply-To: <E1hlHOc-0001UM-0K@gemulon.postgresql.org>
  References: <E1hlHOc-0001UM-0K@gemulon.postgresql.org>

* 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