Skip to content

Instantly share code, notes, and snippets.

@dcragusa
Last active May 1, 2018 07:00
Show Gist options
  • Save dcragusa/12bf05e0c98a6c6f6ae8843f9f82fa63 to your computer and use it in GitHub Desktop.
Save dcragusa/12bf05e0c98a6c6f6ae8843f9f82fa63 to your computer and use it in GitHub Desktop.
View and deal with stuck queries on Postgres
-- View activity
select datname,usename,pid,client_addr,waiting,query_start,query from pg_stat_activity;
-- View locks
select * from pg_locks where relation=(select oid from pg_class where relname='tablename_str');
select pg_cancel_backend(pid_int); -- ask nicely
select pg_terminate_backend(pid_int); -- rude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment