GreenPlum 锁解决

GreenPlum 锁解决

postgresql锁机制

表级锁
  • 访问共享(ACCESS SHARE) - SELECT 命令可在查询中引用的表上获得该锁。一般规则是所有的查询中只有读表才获取此锁。仅与ACCESS EXCLUSIVE独占锁冲突。
  • 行共享(ROW SHARE) - SELECT FOR UPDATE 和 SELECT FOR SHARE 命令可在目标表上获得该锁(以及查询中所有引用的表的访问共享锁)。与ACCESS EXCLUSIVE独占锁EXCLUSIVE排它锁冲突
  • 行独占(ROW EXCLUSIVE) - UPDATE、INSERT 和 DELETE 命令在目标表上获得该锁(以及查询中所有引用的表的访问共享锁)。 一般规则是所有修改表的查询获得该锁。
  • 共享更新独占(SHARE UPDATE EXCLUSIVE) - VACUUM(不含FULL),ANALYZE,CREATE INDEX CONCURRENTLY,和一些 ALTER TABLE 的命令获得该锁。
  • 共享(SHARE) - CREATE INDEX 命令在查询中引用的表上获得该锁。
  • 共享行独占(SHARE ROW EXCLUSIVE) - 任何PostgreSQL命令都不会自动获取此锁定模式。
  • 排他(EXCLUSIVE) - 该模式仅允许并发的ACCESS SHARE锁定,即,只有对表的读动作可以和持有这个锁模式的事务并发执行。在GP中排它锁由 delete,update引起。insert引起行独占
  • 访问独占(ACCESS EXCLUSIVE) - ALTER TABLE,DROP TABLE,TRUNCATE,REINDEX,CLUSTER 和 VACUUM FULL 命令在查询中引用的表上获得该锁。此锁模式是 LOCK 命令的默认模式。

每个锁模式的最重要的信息是与彼此冲突的模式列表。在同一时间同一个表中,2 个事务不能同时保持相冲突的锁模式。事务永远不会与自身发生冲突。 非冲突的锁可以支持多事务并发。同样重要的是要知道有的模式和自身冲突。一些锁模式在获得后会持续到事务结束。但如果锁是在建立一个保存点后获得,保存点回滚后锁会被立刻释放。 下面的表格展示了哪些模式是互相冲突的:

  1. 两个事物不能同时在同一张表上持有冲突模式的锁。
  2. 事物永远不会与其自身冲突。它可能会获得ACCESS EXCLUSIVE锁,然后又会在同一表上获得ACCESS SHARE锁。
  3. 许多事务可以同时持有非冲突锁模式。某些锁定模式是自冲突的(例如,一次不能由一个以上的事务持有ACCESS EXCLUSIVE锁定),而另一些则不是自冲突的(例如,可以由以下方式持有ACCESS SHARE锁定)
    image-20200325170438921.png
行级锁
  • 更新(FOR UPDATE) - 这种模式导致 SELECT 读取的行的更新被锁定。这可以防止它们被其他事务锁定,修改或删除。即尝试 UPDATE、DELETE、SELECT FOR UPDATE、SELECT FOR NO KEY UPDATE、SELECT FOR SHARE 或 SELECT FOR KEY SHARE 的其他事务将被阻塞。删除一行,更新一些列也可以获得到此种锁模式(目前的列集是指那些具有唯一索引,并且可被用作外键 - 但将来这可能会改变)。
  • 无键更新(FOR NO KEY UPDATE) - 这种模式与 FOR UPDATE 相似,但是更弱 - 它不会阻塞SELECT FOR KEY SHARE 锁模式。它通过不获取更新锁的 UPDATE 命令获得。
  • 共享(FOR SHARE) - 这种模式与无键更新锁类似,除了它可以获取共享锁(非排他)。一个共享锁阻止其他事务在这些行上进行 UPDATE,DELETE,SELECT FOR UPDATE 或 SELECT FOR NO KEY UPDATE 操作,但并不阻止它们进行 SELECT FOR SHARE 或 SELECT FOR KEY SHARE。
  • 键共享(FOR KEY SHARE)- 行为类似于共享,但该锁是较弱的:阻止了 SELECT FOR UPDATE,但不阻止 SELECT FOR NO KEY UPDATE。一个键共享锁阻止其他事务进行 DELETE 或任何更改该键值的 UPDATE,但不妨碍任何其他 UPDATE、SELECT FOR NO KEY UPDATE、SELECT FOR SHARE 或者SELECT FOR KEY SHARE。

即使在不同的子事务中,事务也可以在同一行上持有冲突的锁。但是除此之外,两个事务永远不能在同一行上持有冲突的锁。行级锁不影响数据查询。它们仅阻值在同一行数据做写操作。

在这里插入图片描述

锁视图工具

提供相关视图,用于排查锁

  • pg_stat_activity
    在这里插入图片描述
    state
Current overall state of this backend. Possible values are:
active: The backend is executing a query.

idle: The backend is waiting for a new client command.

idle in transaction: The backend is in a transaction, but is not currently executing a query.

idle in transaction (aborted): This state is similar to idle in transaction, except one of the statements in the transaction caused an error.

fastpath function call: The backend is executing a fast-path function.

disabled: This state is reported if track_activities is disabled in this backend.

pg_locks

pg_locks显示独立系统的普通锁管理器和谓词锁管理器的数据.pg_locks对每个活跃的可锁定对象、请求的锁模式、 以及相关的事务保存一行。因此,如果多个事务持有或者等待对同一个对象的锁, 那么同一个可锁定的对象可能出现多次。不过,一个目前没有锁在其上的对象将肯定不会出现。
在这里插入图片描述

# pid字段可以和pg_stat_activity 视图的pid字段连接起来获取持有或者等待持有每个锁的会话的更多信息
SELECT * FROM pg_locks pl LEFT JOIN pg_stat_activity psa
    ON pl.pid = psa.pid;

greenplum锁相关工具

  • gp_toolkit
    在这里插入图片描述

解锁方式

使用pg_stat_activity和gp_locks_on_relation
# 查找到锁住的语句
select * from pg_stat_activity where waiting_reason='lock';
--datid|datname|pid |sess_id|usesysid|usename |application_name|client_addr   |client_hostname|client_port|backend_start      |xact_start         |query_start        |state_change       |waiting|state |backend_xid|backend_xmin|query                               |waiting_reason|rsgid|rsgname|rsgqueueduration|
-------|-------|----|-------|--------|--------|----------------|--------------|---------------|-----------|-------------------|-------------------|-------------------|-------------------|-------|------|-----------|------------|------------------------------------|--------------|-----|-------|----------------|
--16385|cabbeen|3124| 537802|   16384|cabbeenc|Navicat         |218.107.11.199|               |      53250|2020-03-25 14:29:07|2020-03-25 14:29:12|2020-03-25 14:29:30|2020-03-25 14:29:30|true   |active|           |1229747     |truncate table cabbeen_perm.iam_user|lock          |    0|unknown|                |

# 根据执行的语句中的表,找到被锁住的表所在程序的lorpid
select * from gp_toolkit.gp_locks_on_relation where lorrelname like '%iam_user%';
--lorlocktype|lordatabase|lorrelname|lorrelation|lortransaction|lorpid|lormode            |lorgranted|lorcurrentquery                     |
-------------|-----------|----------|-----------|--------------|------|-------------------|----------|------------------------------------|
--relation   |      16385|iam_user  |      21325|              |  3124|AccessExclusiveLock|false     |truncate table cabbeen_perm.iam_user|
--relation   |      16385|iam_user  |      21325|              | 19865|AccessExclusiveLock|true      |lock table cabbeen_perm.iam_user    |
查看segment级别的锁

此粒度更细。

master节点:
查看segment锁情况
select gp_execution_dbid(), pid, relation::regclass, locktype, mode, granted 
from gp_dist_random('pg_locks');
查看具体什么语句持有的锁
select gp_execution_dbid() dbid,pid procpid,query current_query
from gp_dist_random('pg_stat_activity')  
where pid in  
(select pid from gp_dist_random('pg_locks') where locktype='relation' and mode='ExclusiveLock');
通过以上语句大概定位到持有锁的segment
 
segment节点:
根据实际情况进行处理
1.连接相关segment,xxxx替换为实际segment节点的ip,端口,库名
PGOPTIONS="-c gp_session_role=utility" psql -h xxxxxxxxx -p xxxx -d  xxxxx
2.在segment查询相关锁情况
SELECT
w.query as waiting_query,
w.pid as w_pid,
w.usename as w_user,
l.query as locking_query,
l.pid as l_pid,
l.usename as l_user,
t.schemaname || '.' || t.relname as tablename
from pg_stat_activity w
join pg_locks l1 on w.pid = l1.pid and not l1.granted
join pg_locks l2 on l1.relation = l2.relation and l2.granted
join pg_stat_activity l on l2.pid = l.pid
join pg_stat_user_tables t on l1.relation = t.relid
where w.waiting;
3.处理持有锁的pid
select pg_terminate_backend('procpid');
---------------------
--GP查看锁
SELECT pid,rolname, rsqname, granted,
current_query, datname
FROM pg_roles, gp_toolkit.gp_resqueue_status, pg_locks, pg_stat_activity
WHERE pg_roles.rolresqueue=pg_locks.objid
AND pg_locks.objid=gp_toolkit.gp_resqueue_status.queueid
AND pg_stat_activity.procpid=pg_locks.pid;
 
--GP解除锁定
pg_cancel_backend(#pid)
完整的查询语句

可以根据优先级找到锁,并包含锁的详细信息。推荐使用

with    
t_wait as    
(    
  select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted,   
  a.objid,a.objsubid,a.pid,a.transactionid,a.mppsessionid,a.mppiswriter,a.gp_segment_id,     
  b.pid procpid,b.sess_id,b.waiting_reason,b.query current_query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name   
    from pg_locks a,pg_stat_activity b where a.mppsessionid=b.sess_id and not a.granted   
),   
t_run as   
(   
  select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted,   
  a.objid,a.objsubid,a.pid,a.transactionid,a.mppsessionid,a.mppiswriter,a.gp_segment_id,     
  b.pid procpid,b.sess_id,b.waiting_reason,b.query current_query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name   
    from pg_locks a,pg_stat_activity b where a.mppsessionid=b.sess_id and a.granted   
),   
t_overlap as   
(   
  select r.* from t_wait w join t_run r on   
  (   
    r.locktype is not distinct from w.locktype and   
    r.database is not distinct from w.database and   
    r.relation is not distinct from w.relation and   
    r.page is not distinct from w.page and   
    r.tuple is not distinct from w.tuple and   
    r.transactionid is not distinct from w.transactionid and   
    r.classid is not distinct from w.classid and   
    r.objid is not distinct from w.objid and   
    r.objsubid is not distinct from w.objsubid and   
    r.mppsessionid <> w.mppsessionid   
  )    
),    
t_unionall as    
(    
  select r.* from t_overlap r    
  union all    
  select w.* from t_wait w    
)    
select locktype,datname,relation::regclass,page,tuple,textin(xidout(transactionid)),classid::regclass,objid,objsubid,   
string_agg(   
'Gp_Segment_Id: '||case when gp_segment_id is null then 'NULL' else gp_segment_id::text end||chr(10)|| 
'MppIsWriter: '||case when mppiswriter is null then 'NULL' when mppiswriter is true then 'TRUE' else 'FALSE' end||chr(10)|| 
'MppSessionId: '||case when mppsessionid is null then 'NULL' else mppsessionid::text end||chr(10)|| 
'ProcPid: '||case when procpid is null then 'NULL' else procpid::text end||chr(10)|| 
'Pid: '||case when pid is null then 'NULL' else pid::text end||chr(10)||   
'Lock_Granted: '||case when granted is null then 'NULL' when granted is true then 'TRUE' else 'FALSE' end||' , Mode: '||case when mode is null then 'NULL' else mode::text end||' , Waiting_Reason: '||case when waiting_reason is null then 'NULL' else waiting_reason::text end||chr(10)||   
'Username: '||case when usename is null then 'NULL' else usename::text end||' , Database: '||case when datname is null then 'NULL' else datname::text end||' , Client_Addr: '||case when client_addr is null then 'NULL' else client_addr::text end||' , Client_Port: '||case when client_port is null then 'NULL' else client_port::text end||' , Application_Name: '||case when application_name is null then 'NULL' else application_name::text end||chr(10)||    
'Xact_Start: '||case when xact_start is null then 'NULL' else xact_start::text end||' , Query_Start: '||case when query_start is null then 'NULL' else query_start::text end||' , Xact_Elapse: '||case when (now()-xact_start) is null then 'NULL' else (now()-xact_start)::text end||' , Query_Elapse: '||case when (now()-query_start) is null then 'NULL' else (now()-query_start)::text end||chr(10)||    
'SQL (Current SQL in Transaction): '||chr(10)||  
case when current_query is null then 'NULL' else current_query::text end,    
chr(10)||'--------'||chr(10)    
order by    
  (  case mode    
    when 'INVALID' then 0   
    when 'AccessShareLock' then 1   
    when 'RowShareLock' then 2   
    when 'RowExclusiveLock' then 3   
    when 'ShareUpdateExclusiveLock' then 4   
    when 'ShareLock' then 5   
    when 'ShareRowExclusiveLock' then 6   
    when 'ExclusiveLock' then 7   
    when 'AccessExclusiveLock' then 8   
    else 0   
  end  ) desc,   
  (case when granted then 0 else 1 end)  
) as lock_conflict  
from t_unionall   
group by   
locktype,datname,relation::regclass,page,tuple,textin(xidout(transactionid)),classid::regclass,objid,objsubid;
 查找到对应的pid之后,使用select pg_terminate_backend(pid);进行终止。
  1. 使用greenplum的全局锁检测机制

    ​ Greenplum数据库全局死锁检测器后端进程会收集所有segment上的锁信息,并使用有向算法来检测本地死锁和全局死锁是否存在。 该算法使Greenplum数据库放宽对堆表的并发更新和删除限制。 (Greenplum数据库仍然在AO / CO表上使用表级锁定,对UPDATE, DELETE, 和 SELECT…FOR UPDATE的并发操作进行限制。)

    默认情况下,全局死锁检测器是被禁用的,Greenplum数据库以串行方式对堆表执行并发更新和删除操作。 可以通过设置配置参数gp_enable_global_deadlock_detector,开启并发更新并让全局死锁检测器检测死锁是否存在。
    启用全局死锁检测器后,当启动Greenplum数据库时,master 主机上会自动启动一个后端进程。可以通过 gp_global_deadlock_detector_period配置参数,来设置采集和分析锁等待数据的时间间隔。
    如果全局死锁检测器发现了死锁,它会通过取消最新的事务所关联的一个或多个后端进程来避免死锁。
    当全局死锁检测器发现了以下事物类型的死锁时,只有一个事务将成功。其他事务将失败,并打印错误指出不允许对同一行进行并发更新。

    • 在同一行堆表的并发事务中,第一个事务是更新操作,下一个事务执行更新或删除,并且查询计划包含一个动作操作符。
    • 堆表的同一分发键上的并发更新事务由Greenplum Database Postgres查询优化器执行
    • 哈希表的同一行上的并发事务更新由GPORCA优化器执行。

    Greenplum数据库通过配置参数deadlock_timeout指定本地死锁检测的间隔。由于本地死锁检测和全局死锁检测算法的不同,被死锁检测器终止的进程也不同,这取决于本地死锁检测和全局死锁检测哪个先被触发。

    若打开配置参数 lock_timeout,且将数值设定为小于deadlock_timeoutgp_global_deadlock_detector_period,查询会在死锁检测被触发之前就被终止

解锁实操

  1. 例子

    postgres=# create table user_lock(id int primary key, name text); 
    CREATE TABLE
    postgres=# insert into user_lock values (1,'xiaoming');
    INSERT 0 1
    
  2. 会话A

    postgres=# begin;
    BEGIN
     
    postgres=# update user_lock set name='xiaozhang' where id=1; 
    UPDATE 1
    postgres=# select * from user_lock;  
     id |   name    
    ----+-----------
      1 | xiaozhang 
    (1 row)
    
    1. 会话B
    postgres=# begin; 
    BEGIN
     
    postgres=# select * from user_lock;
     id |   name   
    ----+----------
      1 | xiaoming 
    (1 row)
     
    
    1. 会话C
    postgres=# begin;
    BEGIN
     
    postgres=# insert into user_lock values (2,'xiaowang');  
    
    
    1. 会话D
    postgres=# begin;
    BEGIN
     
    postgres=# truncate user_lock;
    
    1. 会话F
    postgres=# begin;
    BEGIN
     
    postgres=# select * from user_lock;
    
    
    with    
    t_wait as    
    (    
      select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted,   
      a.objid,a.objsubid,a.pid,a.transactionid,a.mppsessionid,a.mppiswriter,a.gp_segment_id,     
      b.pid procpid,b.sess_id,b.waiting_reason,b.query current_query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name   
        from pg_locks a,pg_stat_activity b where a.mppsessionid=b.sess_id and not a.granted   
    ),   
    t_run as   
    (   
      select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted,   
      a.objid,a.objsubid,a.pid,a.transactionid,a.mppsessionid,a.mppiswriter,a.gp_segment_id,     
      b.pid procpid,b.sess_id,b.waiting_reason,b.query current_query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name   
        from pg_locks a,pg_stat_activity b where a.mppsessionid=b.sess_id and a.granted   
    ),   
    t_overlap as   
    (   
      select r.* from t_wait w join t_run r on   
      (   
        r.locktype is not distinct from w.locktype and   
        r.database is not distinct from w.database and   
        r.relation is not distinct from w.relation and   
        r.page is not distinct from w.page and   
        r.tuple is not distinct from w.tuple and   
        r.transactionid is not distinct from w.transactionid and   
        r.classid is not distinct from w.classid and   
        r.objid is not distinct from w.objid and   
        r.objsubid is not distinct from w.objsubid and   
        r.mppsessionid <> w.mppsessionid   
      )    
    ),    
    t_unionall as    
    (    
      select r.* from t_overlap r    
      union all    
      select w.* from t_wait w    
    )    
    select locktype,datname,relation::regclass,page,tuple,textin(xidout(transactionid)),classid::regclass,objid,objsubid,   
    string_agg(   
    'Gp_Segment_Id: '||case when gp_segment_id is null then 'NULL' else gp_segment_id::text end||chr(10)|| 
    'MppIsWriter: '||case when mppiswriter is null then 'NULL' when mppiswriter is true then 'TRUE' else 'FALSE' end||chr(10)|| 
    'MppSessionId: '||case when mppsessionid is null then 'NULL' else mppsessionid::text end||chr(10)|| 
    'ProcPid: '||case when procpid is null then 'NULL' else procpid::text end||chr(10)|| 
    'Pid: '||case when pid is null then 'NULL' else pid::text end||chr(10)||   
    'Lock_Granted: '||case when granted is null then 'NULL' when granted is true then 'TRUE' else 'FALSE' end||' , Mode: '||case when mode is null then 'NULL' else mode::text end||' , Waiting_Reason: '||case when waiting_reason is null then 'NULL' else waiting_reason::text end||chr(10)||   
    'Username: '||case when usename is null then 'NULL' else usename::text end||' , Database: '||case when datname is null then 'NULL' else datname::text end||' , Client_Addr: '||case when client_addr is null then 'NULL' else client_addr::text end||' , Client_Port: '||case when client_port is null then 'NULL' else client_port::text end||' , Application_Name: '||case when application_name is null then 'NULL' else application_name::text end||chr(10)||    
    'Xact_Start: '||case when xact_start is null then 'NULL' else xact_start::text end||' , Query_Start: '||case when query_start is null then 'NULL' else query_start::text end||' , Xact_Elapse: '||case when (now()-xact_start) is null then 'NULL' else (now()-xact_start)::text end||' , Query_Elapse: '||case when (now()-query_start) is null then 'NULL' else (now()-query_start)::text end||chr(10)||    
    'SQL (Current SQL in Transaction): '||chr(10)||  
    case when current_query is null then 'NULL' else current_query::text end,    
    chr(10)||'--------'||chr(10)    
    order by    
      (  case mode    
        when 'INVALID' then 0   
        when 'AccessShareLock' then 1   
        when 'RowShareLock' then 2   
        when 'RowExclusiveLock' then 3   
        when 'ShareUpdateExclusiveLock' then 4   
        when 'ShareLock' then 5   
        when 'ShareRowExclusiveLock' then 6   
        when 'ExclusiveLock' then 7   
        when 'AccessExclusiveLock' then 8   
        else 0   
      end  ) desc,   
      (case when granted then 0 else 1 end)  
    ) as lock_conflict  
    from t_unionall   
    group by   
    locktype,datname,relation::regclass,page,tuple,textin(xidout(transactionid)),classid::regclass,objid,objsubid;
    

    关注gp_segment_id=-1的,长时间等待,杀掉procpid即可

    select pg_terminate_backend(67043);
    
    select pg_terminate_backend(66212);
    
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 102
ProcPid: 67043
Pid: 67043
Lock_Granted: FALSE , Mode: AccessExclusiveLock , Waiting_Reason: lock
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58145 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:24:08.476479+08 , Query_Start: 2020-03-25 18:24:27.171855+08 , Xact_Elapse: 00:03:35.860149 , Query_Elapse: 00:03:17.164773
SQL (Current SQL in Transaction): 
truncate user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 66212
Lock_Granted: TRUE , Mode: ExclusiveLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 66212
Lock_Granted: TRUE , Mode: ExclusiveLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 66212
Lock_Granted: TRUE , Mode: ExclusiveLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 73291
Lock_Granted: TRUE , Mode: RowExclusiveLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 73291
Lock_Granted: TRUE , Mode: RowExclusiveLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 73291
Lock_Granted: TRUE , Mode: RowExclusiveLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 100
ProcPid: 66491
Pid: 66491
Lock_Granted: FALSE , Mode: RowExclusiveLock , Waiting_Reason: lock
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58032 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:22:30.667718+08 , Query_Start: 2020-03-25 18:23:01.557594+08 , Xact_Elapse: 00:05:13.66891 , Query_Elapse: 00:04:42.779034
SQL (Current SQL in Transaction): 
insert into user_lock values (2,'xiaowang')
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 99
ProcPid: 66467
Pid: 66467
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58030 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:21:57.6995+08 , Query_Start: 2020-03-25 18:22:14.592235+08 , Xact_Elapse: 00:05:46.637128 , Query_Elapse: 00:05:29.744393
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 73291
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 66212
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 99
ProcPid: 66467
Pid: 73330
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58030 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:21:57.6995+08 , Query_Start: 2020-03-25 18:22:14.592235+08 , Xact_Elapse: 00:05:46.637128 , Query_Elapse: 00:05:29.744393
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 66212
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 99
ProcPid: 66467
Pid: 66467
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58030 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:21:57.6995+08 , Query_Start: 2020-03-25 18:22:14.592235+08 , Xact_Elapse: 00:05:46.637128 , Query_Elapse: 00:05:29.744393
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 99
ProcPid: 66467
Pid: 66467
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58030 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:21:57.6995+08 , Query_Start: 2020-03-25 18:22:14.592235+08 , Xact_Elapse: 00:05:46.637128 , Query_Elapse: 00:05:29.744393
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 73291
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 99
ProcPid: 66467
Pid: 73330
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58030 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:21:57.6995+08 , Query_Start: 2020-03-25 18:22:14.592235+08 , Xact_Elapse: 00:05:46.637128 , Query_Elapse: 00:05:29.744393
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 99
ProcPid: 66467
Pid: 73330
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58030 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:21:57.6995+08 , Query_Start: 2020-03-25 18:22:14.592235+08 , Xact_Elapse: 00:05:46.637128 , Query_Elapse: 00:05:29.744393
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: 0
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 73291
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 98
ProcPid: 66212
Pid: 66212
Lock_Granted: TRUE , Mode: AccessShareLock , Waiting_Reason: NULL
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 57987 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:20:27.018885+08 , Query_Start: 2020-03-25 18:21:27.602971+08 , Xact_Elapse: 00:07:17.317743 , Query_Elapse: 00:06:16.733657
SQL (Current SQL in Transaction): 
select * from user_lock
--------
Gp_Segment_Id: -1
MppIsWriter: TRUE
MppSessionId: 101
ProcPid: 67023
Pid: 67023
Lock_Granted: FALSE , Mode: AccessShareLock , Waiting_Reason: lock
Username: cabbeenc , Database: postgres , Client_Addr: 172.20.0.11/32 , Client_Port: 58142 , Application_Name: Navicat
Xact_Start: 2020-03-25 18:24:35.455702+08 , Query_Start: 2020-03-25 18:24:47.450631+08 , Xact_Elapse: 00:03:08.880926 , Query_Elapse: 00:02:56.885997
SQL (Current SQL in Transaction): 
select * from user_lock

参考:

  • https://www.postgresql.org/docs/9.4/explicit-locking.html
  • http://www.postgres.cn/docs/9.4/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW
  • http://postgres.cn/docs/9.4/view-pg-locks.html
  • https://developer.aliyun.com/article/700364?spm=a2c6h.13262185.0.0.4cac622fPB5CWY
  • https://github.com/digoal/blog/blob/master/201705/20170521_01.md?spm=a2c6h.12873639.0.0.213d199f5iG17M&file=20170521_01.md
发布了13 篇原创文章 · 获赞 0 · 访问量 902
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览