agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add log_statement_max_length GUC to limit logged statement text
Date: Thu, 02 Jul 2026 23:49:05 +0000
Message-ID: <E1wfR9V-0017L7-17@gemulon.postgresql.org> (raw)
Add log_statement_max_length GUC to limit logged statement text
Very large statements can make server logs grow unexpectedly. This is
particularly painful when applications accidentally or intentionally
send huge literal values and statement logging is enabled: the full
statement text may be written to the log even when DBA sees only
its leading part is useful for normal operations.
This commit adds log_statement_max_length GUC that limits the number
of bytes of statement text emitted by statement logging. The setting
applies to statements logged by log_statement, log_min_duration_statement,
log_min_duration_sample, and log_transaction_sample_rate. A positive
value truncates the logged statement body to at most that many bytes,
zero logs an empty statement body, and the default value -1 preserves
the existing behavior of logging statements in full.
Truncation is byte-based, matching the GUC unit, but it clips only
at multibyte character boundaries so that the log output remains valid.
This setting does not affect statements logged because of
log_min_error_statement; handling error-statement logging can be
considered separately.
Author: Jim Jones <jim.jones@uni-muenster.de>
Author: Kirill Gavrilov <diphantxm@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Maxym Kharchenko <maxymkharchenko@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CA+E0NR4S+NC6+QHyY_vUuQZMzLhKqczMx-jJVqtjAxF6+=JwAA@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/c8bd8387c27ab0e60a7864d231f06e8c3fdbfa8d
Modified Files
--------------
doc/src/sgml/config.sgml | 25 +++
src/backend/tcop/postgres.c | 171 ++++++++++++++++-----
src/backend/utils/misc/guc_parameters.dat | 10 ++
src/backend/utils/misc/guc_tables.c | 1 +
src/backend/utils/misc/postgresql.conf.sample | 3 +
src/include/utils/guc.h | 1 +
src/test/modules/test_misc/meson.build | 1 +
.../test_misc/t/014_log_statement_max_length.pl | 115 ++++++++++++++
8 files changed, 289 insertions(+), 38 deletions(-)
Message-ID: <E1wfR9V-0017L7-17@gemulon.postgresql.org>
Permalink: ../E1wfR9V-0017L7-17@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wfR9V-0017L7-17@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 using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Add log_statement_max_length GUC to limit logged statement text
In-Reply-To: <E1wfR9V-0017L7-17@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox