Re: Additional message in pg_terminate_backend

Поиск
Список
Период
Сортировка
От Jim Jones
Тема Re: Additional message in pg_terminate_backend
Дата
Msg-id f1e805d4-eb48-4ebb-ad4f-269ebb8d139b@uni-muenster.de
обсуждение исходный текст
Ответ на Re: Additional message in pg_terminate_backend  (Roman Khapov <rkhapov@yandex-team.ru>)
Список pgsql-hackers
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



В списке pgsql-hackers по дате отправления: