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 1vnBfg-003RTL-0v for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 08:22:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnBfe-003yeT-1W for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 08:22:02 +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 1vnBfe-003yeL-0S for pgsql-hackers@lists.postgresql.org; Tue, 03 Feb 2026 08:22:02 +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 1vnBfc-00000000JyM-0iRl for pgsql-hackers@lists.postgresql.org; Tue, 03 Feb 2026 08:22:01 +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=1770106921; x=1801642921; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=pUnbKCQq7BzIiNnK1vtqlzW1zRETHzfC2pAGRyadcT0=; b=Wy1XXcyFUCd97PjcatqVtppaQUCfF7cNcOKbBGf+7ExKBcRre0tu9ieY OfusGmAgUv/MQ1UBLZtyFVU0mTHZTtUe1Bxb0YA0nIhzxJ/AeINgTe4FR nymqPzO3E48sc7IT9+QAr6MLqPRHp2Q4kc/LX/ZwPzbofNolntTpC5dVa 8kVDQKMkK+t+ykZ1ypzNaO2j0nUTi/A1j3/CuO4sCjUNd3N6mybvc8ZBR e7VyuFfXPXs+zq9fs5yPWCdhb5h1+tRIqU4F2p3RhIPk42jkRzmwhVObd a6tp6bgPif5e1ptwbrvPBJVayla6Bj6DWbq63619d0QuzNnbij+OM0pHs A==; X-CSE-ConnectionGUID: NgMnd3rOSq+tfDn/Xy9v/A== X-CSE-MsgGUID: pwNG+25dQJONny87IDWmiQ== X-IronPort-AV: E=Sophos;i="6.21,270,1763420400"; d="scan'208";a="383431164" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY2.UNI-MUENSTER.DE with ESMTP; 03 Feb 2026 09:21:59 +0100 Received: from [192.168.178.27] (dynamic-093-132-089-216.93.132.pool.telefonica.de [93.132.89.216]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id 43B8420ADF0D; Tue, 3 Feb 2026 09:21:58 +0100 (CET) Message-ID: Date: Tue, 3 Feb 2026 09:21:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Additional message in pg_terminate_backend To: Roman Khapov Cc: Kirill Reshke , Daniel Gustafsson , pgsql-hackers@lists.postgresql.org References: <064E214D-D86F-4917-A0B6-67EAD6BCB24A@yandex-team.ru> <99f3524c-6aee-4fe2-8f3f-fcf0b67642c2@uni-muenster.de> <7e8c913b-1bfb-41f1-b5db-c29e2af48daa@uni-muenster.de> Content-Language: de-DE, en-GB 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/02/2026 08:52, Roman Khapov wrote: > The message is truncated inside BackendMsgSet function, so I see a little > point in truncating it at pg_terminate_backend.. Thanks for the update! You might have a point there. One issue I see is with UTF8 character boundaries. Calculating len like this can lead to invalid characters, for instance: postgres=# SELECT pg_terminate_backend(pg_backend_pid(),0,repeat('🐘',1000)); NOTICE: message is too long, truncated to 127 FATAL: terminating connection due to administrator command: 🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘🐘� server closed the connection unexpectedly This probably means the server terminated abnormally You might wanna take a look at other alternatives, such as pg_mbcliplen, for instance (pseudocode): len = strlen(msg); if (len >= sizeof(slot->msg)) len = pg_mbcliplen(msg, len, sizeof(slot->msg) - 1); memcpy(slot->msg, msg, len); slot->msg[len] = '\0'; Best, Jim