From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: michael.dobrovnik@groiss.com
Subject: BUG #15787: Statement logging may consume huge amounts of memory when BYTEA parameters are involved.
Date: Tue, 30 Apr 2019 10:27:18 +0000
Message-ID: <15787-3b894962cf5d2040@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 15787
Logged by: Michael Dobrovnik
Email address: michael.dobrovnik@groiss.com
PostgreSQL version: 11.2
Operating system: Windows 10 64 bit, Linux
Description:
Hello,
we are using a BYTEA column to store the contents of (large) files and
retrieve them later on.
On a particular customer system, we were getting memory allocation errors
which were not
a pain to reproduce in our systems. After much ado, we can finally pin it
down to a logging configuration.
The problematic system had log_min_duration=x configured.
So:
On PostgreSQL 11.2 (and 10.6. and 9.6.12 and 9.6.8) one gets memory alloc
errors
when the statement is logged (triggered e.g. via log_min_duration=x or via
log_statement=all in postgresql.conf).
c.f. postgresql.log:
2019-04-30 09:51:52 CEST testdb test100 ERROR: invalid memory alloc request
size 1846358165
2019-04-30 09:51:52 CEST testdb test100 STATEMENT: update doccontent set
content = $1 where oid=$2
the operation fails due to logging. Without logging the operation
succeeds.
Logging tries to write the parameters of the statement, the bytea column is
written out in hex format,
as can be seen in the following line (for a smaller file)
2019-04-30 10:48:41 CEST testdb test100 DETAIL: parameters: $1 =
'\x504b0304140000000....
so the allocation size 1846358165 comes from a file that is about 923179081
bytes in length (plus /minus preamble and trailer)
A warning in the documentation of the logging parameters will definitely be
helpful.
A more robust solution could e.g. be to truncate the bytea values written to
the log at some sensible (configurable) length (and also to read them just
up to that length for logging).
thank you all for your efforts concering PostgreSQL!
kind regards
Michael Dobrovnik
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: noreply@postgresql.org, michael.dobrovnik@groiss.com
Subject: Re: BUG #15787: Statement logging may consume huge amounts of memory when BYTEA parameters are involved.
In-Reply-To: <15787-3b894962cf5d2040@postgresql.org>
References: <15787-3b894962cf5d2040@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