Hi hackers!

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 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.

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_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

After patch and added extension, it is possible to do smth like:
postgres=# select pg_terminate_backend_msg(pg_backend_pid(), 0, ’the message');
FATAL:  terminating connection due to administrator command: the message

The general question I want to ask: can this patches be useful for vanilla 
PostgreSQL?

If so, there are some questions about patch improvements:
 - maybe the message can be delivered to backend by some other way than the 
field in struct PGPROC?
termReasonStr field consumes some shared memory and are used in rare cases
 - names of all new funcs/fields/etc should be changed to some better names
 - new file signalfuncs.h seems like too complicated solutions to define *_impl 
functions, it can be done in
some other files? 

-----
Best regards,
Roman Khapov

Attachment: 0001-termination-msg-in-PGPROC.patch
Description: Binary data

Attachment: 0002-pg_term_reason-POC-for-pg_terminate_backend_msg.patch
Description: Binary data

Reply via email to