Created
September 29, 2020 04:36
-
-
Save iamshanto/08a27cac74a3d4a4ef5ab6ea8ec56978 to your computer and use it in GitHub Desktop.
FIND AND KILL LOCKS ON POSTGRES TABLES.md
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
Source: https://jaketrent.com/post/find-kill-locks-postgres/ | |
# LISTING LOCKS | |
select pid | |
from pg_locks l | |
join pg_class t on l.relation = t.oid | |
where t.relkind = 'r' | |
and t.relname = 'TABLE_NAME'; | |
# MATCHING QUERIES WITH LOCKS | |
select pid, state, usename, query, query_start | |
from pg_stat_activity | |
where pid in ( | |
select pid from pg_locks l | |
join pg_class t on l.relation = t.oid | |
and t.relkind = 'r' | |
where t.relname = 'search_hit' | |
); | |
# KILLING LOCKS | |
SELECT pg_cancel_backend(11929); | |
SELECT pg_terminate_backend(11929); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment