mirror of
https://github.com/RealOrangeOne/notes.git
synced 2024-11-17 06:09:04 +00:00
761 B
761 B
title | tags | link | |
---|---|---|---|
Find and kill long running queries |
|
https://medium.com/little-programming-joys/finding-and-killing-long-running-queries-on-postgres-7c4f0449e86d |
Running queries
View a list of queries running longer than 5 minutes:
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
Also see running queries.
Stopping a given connection
SELECT pg_cancel_backend(pid);
pid
being the relevant value from pg_stat_activity.pid
.
Killing a given connection
SELECT pg_terminate_backend(pid);
Should be avoided, as it's synonymous with kill -9
.