Re: Additional message in pg_terminate_backend - Mailing list pgsql-hackers

From Andrey Borodin
Subject Re: Additional message in pg_terminate_backend
Date
Msg-id 288F67CA-E019-40B6-892F-54B5D000C18D@yandex-team.ru
Whole thread Raw
In response to Additional message in pg_terminate_backend  (Roman Khapov <rkhapov@yandex-team.ru>)
List pgsql-hackers

> On 13 Dec 2025, at 12:44, Roman Khapov <rkhapov@yandex-team.ru> wrote:
>
> Recently I started working on patch for adding additional message from admin
> in pg_terminate_backend for one of our greenplum fork. The main idea is that there must be
> done little investigation every time you see 'FATAL:  terminating connection due to administrator command’ to
understandthe 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
translatorsto build a sentence that precedes termination reason. 

>
> I did POC patches with the next main ideas:
> - lets add termReasonStr field in every PGPROC, that field can be used in ProcessInterrupts()
> - 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_impland 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".
Isit 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.




pgsql-hackers by date:

Previous
From: Andrei Lepikhov
Date:
Subject: Re: Parallel Apply
Next
From: Mihail Nikalayeu
Date:
Subject: Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY