May 2018
Intermediate to advanced
576 pages
30h 25m
English
Sometimes, people start a transaction, run some queries, and then just leave, without ending the transaction. This can leave some system resources in a state where some housekeeping processes can't be run. They may even have done something more serious, such as locking a table, thereby causing immediate denial of service for other users who need that table.
You can use the following query to kill all backends that have an open transaction but have been doing nothing for the last 10 minutes:
SELECT pg_terminate_backend(pid) FROM pg_stat_activityWHERE state = 'idle in transaction' AND current_timestamp - query_start > '10 min';
You can even schedule this to run every minute while you are trying to find the ...