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-03T15:46:46Z
Lists: pgsql-hackers
On Fri, Jul 3, 2026 at 4:34 PM Jim Jones <jim.jones@uni-muenster.de> wrote: > +1 > Nice additions -- the feature gap is obvious, IMHO. > > Are you planning to work on it? I'm drowning in work right now and can > only jump on it next week. I don't have plans to work on those at the moment, so please feel free to take them on if you have time! > I'm not so sure about this one. At this point, isn't "query" already \0 > terminated? I'm also wondering if it could affect pg_mbcliplen() down > the road, since strnlen() can return a different value > (log_statement_max_length + MAX_MULTIBYTE_CHAR_LEN) on large queries -- > not tested yet. Yes, "query" should already be NUL-terminated here. The reason for using strnlen() is not to handle an unterminated string, but to avoid scanning the entire query when it's very large and we only need to know whether it exceeds log_statement_max_length. I think it's fine to pass the bounded length to pg_mbcliplen(). It only needs enough input to find a multibyte-safe clipping point at or before log_statement_max_length, i.e., it doesn't need the full query length. The extra MAX_MULTIBYTE_CHAR_LEN bytes provide enough lookahead to handle a multibyte character boundary correctly. - query_len = strlen(query); + query_len = strnlen(query, + (size_t) log_statement_max_length + MAX_MULTIBYTE_CHAR_LEN); 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 →
-
Fix log_statement_max_length test with verbose logs
- 9bfbf5bf6190 master landed
-
Add log_statement_max_length GUC to limit logged statement text
- c8bd8387c27a master landed
-
Improve user control over truncation of logged bind-parameter values.
- 0b34e7d307e6 13.0 cited