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 1wfYPv-005Vhk-2Z for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jul 2026 07:34:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfYPt-0063zU-1d for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jul 2026 07:34:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfYPt-0063zM-0W for pgsql-hackers@lists.postgresql.org; Fri, 03 Jul 2026 07:34:29 +0000 Received: from udcm-wwu2.uni-muenster.de ([128.176.118.28]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wfYPq-00000001R3h-3JO9 for pgsql-hackers@lists.postgresql.org; Fri, 03 Jul 2026 07:34:28 +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=1783064066; x=1814600066; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=63dWKAfJjPt0B2ZGTvp6f8QcTzLyxKlk3S8s8B1MAvs=; b=nd8paDWHJcHglUyRqxGRHF5BIA4RsDaLGoYjBtxL5yma6sO85k5ONThU cWFFIy1TMIwx2ta7F7pzHpZFtsB14khkjd8LI2nHy5oiO6ix9MMacUi4m pOh36v8DBZZ85nNQpjNHmrzicR93oq07FGMHJU+gCztVWZLJkTBmHVTx8 zWNYiSxiOhyV8Fd2zf0FgptbvSLrpnrfmYgtCj0/e4Yz+tc0J4erIHFZv m4SlXFF8EYlgvvKsor2tuDn4UVKG1OII/pFhVn4bL6gSL0ZOT2y4h4Des S8025ksvnpIlzLxyJCIipGL8iGFnHaixttFCGXLbIkam0Cra6wqkloDkE w==; X-CSE-ConnectionGUID: tZs5uxxRSPaNe4/8FMeWNw== X-CSE-MsgGUID: SMaqizG7Q3WTsUS4A7+gJQ== X-IronPort-AV: E=Sophos;i="6.25,145,1779141600"; d="scan'208";a="399762033" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY2.UNI-MUENSTER.DE with ESMTP; 03 Jul 2026 09:34:24 +0200 Received: from [192.168.178.52] (dynamic-093-133-070-236.93.133.pool.telefonica.de [93.133.70.236]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id B77EB20ADF05; Fri, 3 Jul 2026 09:34:22 +0200 (CEST) Message-ID: Date: Fri, 3 Jul 2026 09:34:22 +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> <0514f233-5f77-469b-88c3-e8eb7487afc2@uni-muenster.de> <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: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 03/07/2026 02:56, Fujii Masao wrote: > Thanks for the review! I've pushed the patch. Awesome. Thanks! > While working on it, I found a few possible follow-up improvements. > > (1) > When log_statement is enabled, executing a prepared statement logs the > prepared query in a DETAIL message. For example: > > =# SET log_statement_max_length TO 10; > =# PREPARE test AS SELECT * FROM pgbench_accounts WHERE aid = $1; > LOG: statement: PREPARE te > =# EXECUTE test(1); > LOG: statement: EXECUTE te > DETAIL: prepare: PREPARE test AS SELECT * FROM pgbench_accounts > WHERE aid = $1; > > Should log_statement_max_length also apply to such query string in the > DETAIL message? > > (2) > When a bind parameter is truncated by > log_parameter_max_length, an ellipsis (...) is appended: > > =# SET log_parameter_max_length TO 5; > =# SELECT $1::text \bind 'abcdefghijk' \g > LOG: execute : SELECT $1::text > DETAIL: Parameters: $1 = 'abcde...' > > Would it make sense for log_statement_max_length to append an > ellipsis as well, so that users can easily tell when a statement has > been truncated? +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. > (3) > + query_len = strlen(query); > > truncate_query_log() uses strlen() only to determine whether the > query exceeds log_statement_max_length. Since the query can be very > large, would it be better to use > > strnlen(query, log_statement_max_length + MAX_MULTIBYTE_CHAR_LEN) > > instead, to avoid scanning the entire string? 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. Thanks! Best, Jim