I just released first version of pg_terminator.
It's a tool that is supposed to be run on PostgreSQL db server, monitor a database, and cancel or terminate offending queries/connections.
It can be used, for example to:
- kill leftover psql sessions that are not doing anything
- cancel too long queries on production servers
- kill connections that have long idle-in-transaction state
- make sure that some application will not use transactions longer than “x"
- and more …
Basically – if you can write a where condition, that operates on pg_stat_activity view, that can list backends to cancel/terminate – you can make pg_terminate do it for you.
To work, it requires Ruby, and its Pg library.
Usage is free, and it's fully open-source (BSD license).