Skip to content

Instantly share code, notes, and snippets.

@benjamin658
Created November 5, 2020 06:10
Show Gist options
  • Save benjamin658/cc4aff9b01e591189d3888ccdcd56bd4 to your computer and use it in GitHub Desktop.
Save benjamin658/cc4aff9b01e591189d3888ccdcd56bd4 to your computer and use it in GitHub Desktop.
PostgreSQL find out slow query and kill it
/* 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;
@benjamin658
Copy link
Author

The best way is still to find out why the slow query exist.
Please use it carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment