PG_LOCKWAIT_DETAIL
PG_LOCKWAIT_DETAIL视图显示当前实例中锁等待链详细信息。如果存在多级的锁等待关系,会依次将整个锁等待链按照等待顺序显示出来。
该视图8.2.1集群版本中8.2.1.251及以上版本支持;9.1.1.100及以上集群版本支持。
| 
        名称  | 
      
        类型  | 
      
        描述  | 
     
|---|---|---|
| 
        level  | 
      
        integer  | 
      
        锁等待链中的层级,以1开始,每显示一层等待关系level会加1。  | 
     
| 
        node_name  | 
      
        name  | 
      
        节点名称,对应pgxc_node表中的node_name列。  | 
     
| 
        lock_wait_hierarchy  | 
      
        text  | 
      
        锁等待链,以节点名称:进程号->等待进程号->等待进程号->...。  | 
     
| 
        lock_type  | 
      
        text  | 
      
        被锁定对象的类型。  | 
     
| 
        database  | 
      
        oid  | 
      
        被锁定对象所在数据库的OID。  | 
     
| 
        relation  | 
      
        oid  | 
      
        被锁定对象关系的OID。  | 
     
| 
        page  | 
      
        integer  | 
      
        关系内部的页面编号。  | 
     
| 
        tuple  | 
      
        smallint  | 
      
        页面的行编号。  | 
     
| 
        virtual_xid  | 
      
        text  | 
      
        事务的虚拟ID。  | 
     
| 
        transaction_id  | 
      
        xid  | 
      
        事务ID。  | 
     
| 
        class_id  | 
      
        oid  | 
      
        包含该对象的系统表的OID。  | 
     
| 
        obj_id  | 
      
        oid  | 
      
        对象在其系统表内的OID。  | 
     
| 
        obj_subid  | 
      
        smallint  | 
      
        对于表的列字段编号。  | 
     
| 
        virtual_transaction  | 
      
        text  | 
      
        持有此锁或者在等待此锁的事务的虚拟ID。  | 
     
| 
        pid  | 
      
        bigint  | 
      
        持有此锁或者等待此锁的线程号。  | 
     
| 
        mode  | 
      
        text  | 
      
        锁级别。  | 
     
| 
        granted  | 
      
        boolean  | 
      
        是否持有锁。  | 
     
| 
        fastpath  | 
      
        boolean  | 
      
        是否通过fastpath机制获得锁。  | 
     
| 
        wait_for_pid  | 
      
        bigint  | 
      
        锁冲突线程的线程号。  | 
     
| 
        conflict_mode  | 
      
        text  | 
      
        锁冲突线程持有的冲突锁级别。  | 
     
| 
        query_id  | 
      
        bigint  | 
      
        查询语句的ID。  | 
     
| 
        query  | 
      
        text  | 
      
        查询语句。  | 
     
| 
        application_name  | 
      
        text  | 
      
        连接到该后端的应用名。  | 
     
| 
        backend_start  | 
      
        timestamp with time zone  | 
      
        后端进程启动时间,即客户端连接服务器的时间。  | 
     
| 
        xact_start  | 
      
        timestamp with time zone  | 
      
        当前事务的启动时间。  | 
     
| 
        query_start  | 
      
        timestamp with time zone  | 
      
        开始当前活跃查询的时间。  | 
     
| 
        state  | 
      
        text  | 
      
        后端当前总体状态。  | 
     
| 
        waittime  | 
      
        timestamp with time zone  | 
      
        开始等待锁的时间戳。  | 
     
| 
        holdtime  | 
      
        timestamp with time zone  | 
      
        开始获取锁的时间戳。  | 
     
应用示例
- 连接DN节点,开启一个事务,执行查询。
     
     
1 2
BEGIN; SELECT * FROM t1;
 - 另一个窗口连接CN,对表t1执行TRUNCATE。
     
     
1TRUNCATE t1;
此时TRUNCATE会被阻塞。
 - 另开一个窗口连接DN,查询PG_LOCKWAIT_DETAIL视图,获得当前的锁等待情况,帮助诊断阻塞原因。
     
     
1 2 3 4 5 6 7 8 9 10
SELECT * FROM PG_LOCKWAIT_DETAIL; level | node_name | lock_wait_hierarchy | lock_type | database | relation | page | tuple | virtual_xid | transaction_id | class_id | obj_id | obj_subid | virtual_transaction | pid | mode | granted | fastpath | wait_for_pid | conflict_mode | query_id | query | application_n ame | backend_start | xact_start | query_start | state | waittime | holdtime -------+-----------+----------------------------------------------+-----------+----------+----------+------+-------+-------------+----------------+----------+--------+-----------+---------------------+-----------------+---------------------+---------+----------+-----------------+-----------------+-------------------+-------------------------+-------------- ----+-------------------------------+-------------------------------+-------------------------------+--------+------------------------------+------------------------------- 1 | datanode1 | datanode1:140371308516512 | relation | 16564 | 25224 | | | | 3956258 | | | | 15/204 | 140371308516512 | AccessExclusiveLock | f | f | 140371308446552 | AccessShareLock | 77687093572143017 | TRUNCATE t1 | coordinator1 | 2025-02-13 15:07:35.168383+08 | 2025-02-13 15:11:23.613945+08 | 2025-02-13 15:11:23.651944+08 | active | 2025-02-13 15:11:23.65369+08 | 2 | datanode1 | datanode1:140371308516512 -> 140371308446552 | relation | 16564 | 25224 | | | | | | | | 13/18 | 140371308446552 | AccessShareLock | t | f | | | 0 | begin;select * from t1; | gsql | 2025-02-13 14:15:58.989993+08 | 2025-02-13 15:10:40.594882+08 | 2025-02-13 15:10:40.594882+08 | active | | 2025-02-13 15:10:40.596243+08 (2 rows)