DM8 DSC事务阻塞处理

会话1:
[dmdba@centos-04 bin]$ disql sysdba/dameng123:1236

服务器[LOCALHOST:1236]:处于普通打开状态
登录使用时间: 12.464(毫秒)
disql V8
SQL> update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE() where C1='500';
影响行数 1

已用时间: 24.414(毫秒). 执行号:144.
#未提交

会话2:
[dmdba@centos-04 ~]$ disql sysdba/dameng123:1236

服务器[LOCALHOST:1236]:处于普通打开状态
登录使用时间: 33.029(毫秒)
disql V8
SQL> update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE();
#被阻塞
会话3:
[dmdba@centos-05 ~]$ disql sysdba/dameng123:1236

服务器[LOCALHOST:1236]:处于普通打开状态
登录使用时间: 33.356(毫秒)
disql V8
SQL> update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE()-1 where C1='300';
#被阻塞

#查看当前库中是否存在阻塞
SQL> select * from v$dsc_trxwait;

行号     EP_SEQNO    ID                   WAIT_FOR_ID          WAIT_SEQNO  WAIT_TIME  
---------- ----------- -------------------- -------------------- ----------- -----------
1          0           43944                43942                0           180780
2          1           43947                43944                0           83033

43942阻塞了43944,43944阻塞了43947,阻塞源头是43942。

#查看阻塞源头
端点0:
select 'sp_close_session('||s.sess_id||');' kill_command,datediff(ss,s.last_recv_time,sysdate) ss, 
       sf_get_session_sql(s.sess_id), s.SESS_ID,s.TRX_ID,s.STATE,s.APPNAME
  from v$sessions  s
 where s.trx_id in (select WAIT_FOR_ID
          from v$dsc_trxwait 
         where WAIT_FOR_ID not in (select ID from v$dsc_trxwait));

KILL_COMMAND                        SS          SF_GET_SESSION_SQL(S.SESS_ID)                                    SESS_ID              TRX_ID               STATE APPNAME
------------------------------      ----------- ---------------------------------------------------------------- -------------------- -------------------- ----- -------
sp_close_session(140250818249696);  1124        update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE() where C1='500'; 140250818249696      43942                IDLE  disql

阻塞源头会话状态为IDLE说明没有正在执行的事物,可能事物执行完后没有提交。
-- 查询未提交事务
 select b.object_name, c.sess_id, c.thrd_id, c.state, c.sql_text, a.*
 from v$lock a, dba_objects b, v$sessions c
where a.table_id = b.object_id 
 and a.ltype = 'OBJECT'
 and a.trx_id = c.trx_id
 and a.ign_flag=0;
OBJECT_NAME     SESS_ID              THRD_ID     STATE  SQL_TEXT                                                        
--------------- -------------------- ----------- ------ ----------------------------------------------------------------
ADDR                 TRX_ID               LTYPE  LMODE BLOCKED     TABLE_ID    ROW_IDX              TID                  IGN_FLAG   
-------------------- -------------------- ------ ----- ----------- ----------- -------------------- -------------------- -----------
HLCK_EP    
-----------
TAB_FOR_RECOVER 140250950346928      4013        ACTIVE update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE();
140251552426064      43944                OBJECT IX    0           1286        0                    0                    0
0


OBJECT_NAME     SESS_ID              THRD_ID     STATE  SQL_TEXT                                                        
--------------- -------------------- ----------- ------ ----------------------------------------------------------------
ADDR                 TRX_ID               LTYPE  LMODE BLOCKED     TABLE_ID    ROW_IDX              TID                  IGN_FLAG   
-------------------- -------------------- ------ ----- ----------- ----------- -------------------- -------------------- -----------
HLCK_EP    
-----------
TAB_FOR_RECOVER 140250818249696      3904        IDLE   update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE() where C1='500';
140251552425936      43942                OBJECT IX    0           1286        0                    0                    0
0
事物id为43942和43944的事物未提交,其中id为43942的事物未阻塞源头
端点0:查看阻塞源头sql为空
--查看被阻塞sql
端点0:
select datediff(ss,last_recv_time,sysdate) ss, 
       sf_get_session_sql(sess_id), 
       s.SESS_ID, 
       s.TRX_ID, 
       s.STATE, 
       s.APPNAME 
  from v$sessions s
 where s.TRX_ID in (select id from v$dsc_trxwait);
SS          SF_GET_SESSION_SQL(SESS_ID)                       SESS_ID              TRX_ID               STATE  APPNAME
----------- ------------------------------------------------- -------------------- -------------------- ------ -------
1199        update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE(); 140250950346928      43944                ACTIVE disql

端点1:
select datediff(ss,last_recv_time,sysdate) ss, 
       sf_get_session_sql(sess_id), 
       s.SESS_ID, 
       s.TRX_ID, 
       s.STATE, 
       s.APPNAME 
  from v$sessions s
 where s.TRX_ID in (select id from v$dsc_trxwait);
SS          SF_GET_SESSION_SQL(SESS_ID)                                        SESS_ID              TRX_ID               STATE  APPNAME
----------- ------------------------------------------------------------------ -------------------- -------------------- ------ -------
1235        update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE()-1 where C1='300'; 1117797632           43947                ACTIVE disql


kill阻塞源头(事物ID为43942):
SQL> sp_close_session(140250818249696);
DMSQL 过程已成功完成

#查看当前库中是否存在阻塞
SQL> select * from v$dsc_trxwait;

EP_SEQNO    ID                   WAIT_FOR_ID          WAIT_SEQNO  WAIT_TIME  
----------- -------------------- -------------------- ----------- -----------
1           43947                43944                0           2387894

kill事物ID为43942的会话后事务ID为43944的会话成为了阻塞源头,提交会话2上事务ID为43944的事务后其他事务正常执行。
会话2:事务ID为43944
SQL> update TAB_FOR_RECOVER set CREATE_TIME=SYSDATE();
影响行数 500

已用时间: 00:40:31.732. 执行号:145.
SQL> commit;
#查看当前库中是否存在阻塞
SQL>  select * from v$dsc_trxwait;
未选定行
已经没有阻塞

达梦在线服务平台:https://eco.dameng.com

你可能感兴趣的:(达梦,达梦,事务,锁阻塞,DSC)