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 1vVpna-008upm-0u for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 11:34:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVpnY-00CNl7-0k for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 11:34:29 +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 1vVpnX-00CNkz-2a for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 11:34:28 +0000 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVpnV-0018dQ-1b for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 11:34:27 +0000 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 00B91C022E for ; Wed, 17 Dec 2025 14:34:21 +0300 (MSK) Received: from smtpclient.apple (unknown [2a02:6bf:8080:66f::1:20]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id JYTUcB2F0qM0-gSee9apO; Wed, 17 Dec 2025 14:34:20 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1765971260; bh=ntde5kU4OV/V6vpIXA5LXJvzuU9zmx/+xfTb44XTZHs=; h=Message-Id:To:Date:References:Cc:In-Reply-To:From:Subject; b=RGkeoJzDxBqPA24u7ryVhbnNTrwYBXy+6n6x7yUl82PVlhzLtpCOQQ0OZtueugHkY D4Cma0szpF5QiwhVN2y0J3+m9EnxepfpCrRQZ2WbD4xXhZO1UTKrJ6NQQI1KY/JKP6 aGunlK8XiUqBQaN/CGBrHuwZa63p3bmCOnig+4oQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Additional message in pg_terminate_backend From: Andrey Borodin In-Reply-To: <064E214D-D86F-4917-A0B6-67EAD6BCB24A@yandex-team.ru> Date: Wed, 17 Dec 2025 16:34:09 +0500 Cc: pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <288F67CA-E019-40B6-892F-54B5D000C18D@yandex-team.ru> References: <064E214D-D86F-4917-A0B6-67EAD6BCB24A@yandex-team.ru> To: Roman Khapov X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 13 Dec 2025, at 12:44, Roman Khapov wrote: >=20 > Recently I started working on patch for adding additional message from = admin=20 > in pg_terminate_backend for one of our greenplum fork. The main idea = is that there must be=20 > done little investigation every time you see 'FATAL: terminating = connection due to administrator command=E2=80=99 to understand the = reason, especially in cases where connection was terminated by another > user. So it was decided to create some new functions, that allows to = terminate connection with > additional message. Overall idea seems good to me. Keep in mind that Postgres literals are translated into many languages. = So text ought to be clear enough for translators to build a sentence = that precedes termination reason. >=20 > I did POC patches with the next main ideas: > - lets add termReasonStr field in every PGPROC, that field can be used = in ProcessInterrupts()=20 > - implementation of pg_terminate_backend/pg_cancel_backend should be = accessible from extensions, so lets move it in = pg_terminate_backend_impl/pg_cancel_backend_impl and add definitions for = it somewhere > - write simple extensions, which defines functions like = pg_terminate_backend_msg, that sets termReasonStr and calls = pg_terminate_backend_impl First thing that we need to do is to agree on API of the new feature. We = do not need core-extension separation for this. My vote would be for having pg_cancel_backend(reason = text)\pg_terminate_backend(reason text) along with parameterless = versions. 32 bytes per PGPROC seems reasonable for a "reason". The patch doesn't = seem to take care of cleaning "termReasonStr". Is it done elsewhere? We have a race condition if many backends cancel same backend. Won't = they mess each other's reason? Thanks! Best regards, Andrey Borodin.