Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfy8I-005p6Y-2T for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 11:02:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfy8G-00A88P-0T for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 11:02:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfy8F-00A88G-2W for pgsql-hackers@lists.postgresql.org; Sat, 04 Jul 2026 11:01:59 +0000 Received: from udcm-wwu2.uni-muenster.de ([128.176.118.28]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wfy8D-00000001RsO-044E for pgsql-hackers@lists.postgresql.org; Sat, 04 Jul 2026 11:01:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-muenster.de; i=@uni-muenster.de; q=dns/txt; s=uniout; t=1783162917; x=1814698917; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=F7k36mXkqpjPn3x/t/OJa9BeX5lFD54CSIji9flYbVY=; b=fbT2wF7xCbStVJXvq1sllccY7RQP/sAyp2i8M9OjuXok5KFzvajMWhY8 t1+Q7T8tUsk7VDem2EwHujrve7/TwHPl9+z/95fkCGlZrowL3dUh/ap+2 Mz46mgEHSJ1B+GDNY8EeZuAyN3sYbrBPn8OUBjlHzXBpmctdU1WQWTmR/ 7QDafxnQczw5dWGZUntC/T3DRHpAI+WCFZOkInaZpxsqyBPij4aRN9CoW Hnfe3RdTfzUcBz/tvT+HARaGiQumw4wFg+i4mPbfa0xq+vKzm2DVcQnNk 48Y5NfvfYQh3vraDOaOiYREOY6ORut3r1sofMfUwEC7TmwPwz6Yuns4ds g==; X-CSE-ConnectionGUID: QL/l70WrRPO/g+84h06KRw== X-CSE-MsgGUID: VeS4PlXYTsCUSGtAsXEAvg== X-IronPort-AV: E=Sophos;i="6.25,147,1779141600"; d="scan'208";a="399867148" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY2.UNI-MUENSTER.DE with ESMTP; 04 Jul 2026 13:01:53 +0200 Received: from [192.168.178.52] (dynamic-077-177-185-027.77.177.pool.telefonica.de [77.177.185.27]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id 8A25E20ADF04; Sat, 4 Jul 2026 13:01:51 +0200 (CEST) Message-ID: <3c40c38c-29fe-4e24-944b-6fe90ade9ffa@uni-muenster.de> Date: Sat, 4 Jul 2026 13:01:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Truncate logs by max_log_size To: Fujii Masao Cc: Maxym Kharchenko , Kirill Reshke , =?UTF-8?Q?=C3=81lvaro_Herrera?= , Fujii Masao , Kirill Gavrilov , "Andrey M. Borodin" , Euler Taveira , pgsql-hackers@lists.postgresql.org References: <202602051012.qer26xklakqb@alvherre.pgsql> <81297eea-8a5c-4cdc-9c49-0524e3968b62@uni-muenster.de> <67fcc68a-fce0-42b8-863f-8db5509d1790@uni-muenster.de> <93f10aa2-4c04-45dd-9810-98c7d2dd9b34@uni-muenster.de> Content-Language: en-US, de-DE From: Jim Jones In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 03/07/2026 17:46, Fujii Masao wrote: > On Fri, Jul 3, 2026 at 4:34 PM Jim Jones 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); All right, thanks for the explanation. I'll give it a try next week. Have a nice weekend! Best, Jim