查找锁

来自 PostgreSQL 维基
跳转到导航跳转到搜索

性能片段

查找锁

适用于 PostgreSQL

任何版本

SQL

依赖于


SELECT
    l1.*,
    l2.virtualtransaction,
    l2.pid,
    l2.mode,
    l2.granted
FROM
    pg_locks l1
JOIN
    pg_locks l2 on (
        (
            l1.locktype,
            l1.database,
            l1.relation,
            l1.page,
            l1.tuple,
            l1.virtualxid,
            l1.transactionid,
            l1.classid,
            l1.objid,
            l1.objsubid
        )
    IS NOT DISTINCT FROM
        (
            l2.locktype,
            l2.database,
            l2.relation,
            l2.page,
            l2.tuple,
            l2.virtualxid,
            l2.transactionid,
            l2.classid,
            l2.objid,
            l2.objsubid
        )
    )
WHERE
    NOT l1.granted
AND
    l2.granted;