How to detect query which holds the lock in Postgres?

前端 未结 5 2049
醉话见心
醉话见心 2020-12-07 08:51

I want to track mutual locks in postgres constantly.

I came across Locks Monitoring article and tried to run the following query:

SELECT bl.pid     A         


        
5条回答
  •  伪装坚强ぢ
    2020-12-07 09:41

    This modification of a_horse_with_no_name's answer will give you the blocking queries in addition to just the blocked sessions:

    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));
    

提交回复
热议问题