How to release possible Postgres row locks?
Solution 1:
It's possible to see the locks.
Here is a view to make it a bit easier than using pg_locks directly:
CREATE OR REPLACE VIEW public.active_locks AS
SELECT t.schemaname,
t.relname,
l.locktype,
l.page,
l.virtualtransaction,
l.pid,
l.mode,
l.granted
FROM pg_locks l
JOIN pg_stat_all_tables t ON l.relation = t.relid
WHERE t.schemaname <> 'pg_toast'::name AND t.schemaname <> 'pg_catalog'::name
ORDER BY t.schemaname, t.relname;
Then you just select from the view:
SELECT * FROM active_locks;
And kill it with:
SELECT pg_cancel_backend('%pid%');
Other solutions: http://wiki.postgresql.org/wiki/Lock_Monitoring
Solution 2:
Simple:
Get the active locks from pg_locks:
SELECT t.relname, l.locktype, page, virtualtransaction, pid, mode, granted
FROM pg_locks l, pg_stat_all_tables t
WHERE l.relation = t.relid
ORDER BY relation asc;
Copy the pid(ex: 14210) from above result and substitute in the below command.
SELECT pg_terminate_backend(14210)