Detect and Fix locked table in postgres
Detect and Fix locked table in postgres
Last update: 2024-06-10
Original post:
https://stackoverflow.com/questions/26489244/how-to-detect-query-which-holds-the-lock-in-postgres
View processes
SELECT
activity.pid,
activity.usename,
activity.query,
blocking.pid AS blocking_id,
blocking.query AS blocking_query
FROM pg_stat_activity AS activity
JOIN pg_stat_activity AS blocking ON blocking.pid = ANY(pg_blocking_pids(activity.pid))
Terminate Proccess
SELECT pg_cancel_backend(215449), pg_terminate_backend(215449);