Created
December 14, 2020 08:50
-
-
Save karolosk/b1ba425f488481c3de0df535742772f9 to your computer and use it in GitHub Desktop.
Find and kill locks in PostgreSQL
This file contains 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 process ids | |
select pid | |
from pg_locks l | |
join pg_class t on l.relation = t.oid | |
where t.relkind = 'r'; | |
-- Find queries that are locked | |
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' | |
); | |
-- Stop the process ids | |
SELECT pg_cancel_backend(pid); | |
-- Force stop the process ids | |
SELECT pg_terminate_backend(pid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment