Se stai usando PostgreSQL 9.6+ puoi usare pg_blocking_pids()
per trovare il PID delle query che bloccano la tua.
select pid, pg_blocking_pids(pid) as blocked_by, query as blocked_query
from pg_stat_activity
where pg_blocking_pids(pid)::text != '{}';