How to Kill Long Running Queries with User Notification in PostgreSQL

postgresqlpostgresql-9.6

Is there any way to inform user that your query has been running more than x minutes, so admin has killed your session. This is especially to the query or read only user.

I have a function which will do exactly what I want (Im running the function periodically). But, I couldn't notice the user that their connection being killed by admin.

Users are using PgAdmin/psql/DBeaver as client. I am not sure, how can I show the message to them. Is there anyway at all notify the user in their session window?

(Initially I tried to do kind of logon trigger. Unfortunately, postgres doesn't have the feature yet)

Best Answer

This feature has been proposed with an implementation, but did not make it into version 12. Maybe it will be in version 13. (If you can test the patch and provide feedback, you can increase the odds of that happening)