Re: Truncate logs by max_log_size

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: Maxym Kharchenko <maxymkharchenko(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Kirill Gavrilov <diphantxm(at)gmail(dot)com>, "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Euler Taveira <euler(at)eulerto(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Truncate logs by max_log_size
Date: 2026-07-02 15:49:24
Message-ID: CAHGQGwHJHCi=4zEyMc4GJWPC9-oQZHj+9kncxS2442V9PXGgoQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, May 15, 2026 at 7:48 PM Jim Jones <jim(dot)jones(at)uni-muenster(dot)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

Attachment Content-Type Size
v14-0001-Add-log_statement_max_length-GUC-to-limit-logged.patch application/octet-stream 17.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-07-02 16:25:23 json/jsonb cleanup + FmgrInfo caching
Previous Message jian he 2026-07-02 15:38:41 Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions