Created
November 5, 2020 06:10
-
-
Save benjamin658/cc4aff9b01e591189d3888ccdcd56bd4 to your computer and use it in GitHub Desktop.
PostgreSQL find out slow query and kill it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Find out the slow query */ | |
SELECT pid, query FROM pg_stat_activity WHERE state = 'active'; | |
/* Kill the slow query by pid */ | |
select pg_terminate_backend(pid) | |
from pg_stat_activity | |
where pid = $pid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The best way is still to find out why the slow query exist.
Please use it carefully.