Re: Truncate logs by max_log_size

Fujii Masao <masao.fujii@gmail.com>

From: Fujii Masao <masao.fujii@gmail.com>
To: Jim Jones <jim.jones@uni-muenster.de>
Cc: Maxym Kharchenko <maxymkharchenko@gmail.com>, Kirill Reshke <reshkekirill@gmail.com>, Álvaro Herrera <alvherre@kurilemu.de>, Fujii Masao <masao.fujii@oss.nttdata.com>, Kirill Gavrilov <diphantxm@gmail.com>, "Andrey M. Borodin" <x4mmm@yandex-team.ru>, Euler Taveira <euler@eulerto.com>, pgsql-hackers@lists.postgresql.org
Date: 2026-07-02T15:49:24Z
Lists: pgsql-hackers

Attachments

On Fri, May 15, 2026 at 7:48 PM Jim Jones <jim.jones@uni-muenster.de> wrote:
>
> rebase due to recent changes in src/test/modules/test_misc/meson.build

I reviewed the patch again and made a few additional changes. The updated
patch is attached. Barring any objections, I'm thinking to commit it.

         If greater than zero, each statement logged by
-        <xref linkend="guc-log-statement"/> or
-        <xref linkend="guc-log-min-duration-statement"/> is truncated to
-        at most this many bytes.
+        <xref linkend="guc-log-statement"/>,
+        <xref linkend="guc-log-min-duration-statement"/>,
+        <xref linkend="guc-log-min-duration-sample"/>, or
+        <xref linkend="guc-log-transaction-sample-rate"/>
+        is truncated to at most this many bytes.

Since this parameter also affects statements logged by
log_min_duration_sample and log_transaction_sample_rate, I added
those parameters to the description.


+        This setting does not affect statements logged because of
+        <xref linkend="guc-log-min-error-statement"/>.

I also clarified that this parameter does not affect statements logged
by log_min_error_statement.


+static char *
+truncate_query_log(const char *query)

Since truncate_query_log() is only used in postgres.c, I moved it
from elog.c and made it a static function.


-ok( $node->log_contains(
- qr/statement: SELECT '123456789ABC(?!D)/, $log_offset),
+ok($node->log_contains(qr/statement: SELECT '123456789ABC$/m, $log_offset),

I tightened the test to verify that the truncated statement ends exactly
at the 20th byte.


-# character (the 🐘 emoji is 4 bytes; with limit=12 it must be kept whole
-# and the following 't' must not appear).
-note "Multibyte truncation respects character boundaries";
+# character when the byte limit falls in the middle of it.
+SKIP:

Using an emoji directly in the test seems fragile and the behavior
may depend on the test platform. To make the test more robust, I changed
it to construct the multibyte character with pack() and run the test
only when the server encoding is UTF-8.

Regards,

-- 
Fujii Masao

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix log_statement_max_length test with verbose logs

  2. Add log_statement_max_length GUC to limit logged statement text

  3. Improve user control over truncation of logged bind-parameter values.