psql -d appdb -c "SELECT pid, pg_blocking_pids(pid) FROM pg_stat_activity;"
Find which sessions block others
For every backend, pg_blocking_pids returns the pids currently blocking it, empty when none. The classic way to find who holds the lock everyone is waiting on. Follow up by inspecting those pids' queries in pg_stat_activity.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.