执行超时会话时,同时执行一个报锁超时的sql
for rec in (select sess_id,
SF_GET_EP_SEQNO(ROWID) a
from v$sessions
where trx_id in (select wait_for_id from v$trxwait)
and port_type=0)
loop
sp_close_session(rec.a,rec.sess_id);
end loop;
end;
:::
:::
:::
如果上面的不行再试试这个
执行超时会话时,同时执行一个报锁超时的sql
select
tw.id as "等待的事务ID",
tw.wait_for_id as "正在运行的事务ID",
s.sess_id as "等待的会话",
ws.sess_id as "正在执行的会话",
s.sql_text as "等待的sql",
ws.sql_text as "正在执行的sql" ,
'SP_CLOSE_SESSION('||ws.sess_id||');' "关闭会话的语句"
from v$trxwait tw left join v$sessions s
on tw.id=s.trx_id
left join v$sessions ws
on tw.wait_for_id=ws.trx_id where s.port_type=0;
其他查询方式
(1)查询delete语句和会话的状态:并查看该delete语句对应的TRX_ID,例如为20187
SELECT * FROM v$sessions where sql_text like ‘delete%t1%’;
(2)查询20187这个事务被哪个事务锁定:查询出产生锁的事务ID,例如为20194
SELECT * FROM v$trxwait WHERE id = 20187;
行号 ID WAIT_FOR_ID WAIT_TIME THRD_ID
1 20187 20194 221348 8880
(3)查询20194这个事务对应的SESS_ID:检查该session的SQL语句是否为业务语句,如果可以停掉在将该会话CLOSE
SELECT * FROM v$trxwait WHERE id = 20194;
159793176这个SESS_ID是20194的SESS_ID
CALL SP_CLOSE_SESSION(159793176);
select sysdate(),ses.INSTANCE_NAME,trx.STATUS,
trx.DEL_CNT,
ses.SESS_ID,
ses.SQL_TEXT,
ses.STATE
from v$trx trx
LEFT JOIN SYS.gV$SESSIONS ses
on trx.SESS_ID=SES.SESS_ID
where TRX.id='5213315174' order by 4 desc ;
SELECT
SYSDATE STATTIME ,
DATEDIFF(SS, S1.LAST_SEND_TIME, SYSDATE) SS,
'被阻塞的信息' WT,S1.SESS_ID WT_SESS_ID ,
S1.SQL_TEXT WT_SQL_TEXT ,
S1.STATE WT_STATE ,
S1.TRX_ID WT_TRX_ID ,
S1.USER_NAME WT_USER_NAME ,
S1.CLNT_IP WT_CLNT_IP ,
S1.APPNAME WT_APPNAME ,
S1.LAST_SEND_TIME WT_LAST_SEND_TIME ,
'引起阻塞的信息' FM ,
S2.SESS_ID FM_SESS_ID ,
S2.SQL_TEXT FM_SQL_TEXT ,
S2.STATE FM_STATE ,
S2.TRX_ID FM_TRX_ID ,
S2.USER_NAME FM_USER_NAME ,
S2.CLNT_IP FM_CLNT_IP ,
S2.APPNAME FM_APPNAME ,
S2.LAST_SEND_TIME FM_LAST_SEND_TIME
FROM
V$SESSIONS S1,
V$SESSIONS S2,
V$TRXWAIT W
WHERE
S1.TRX_ID=W.ID
AND S2.TRX_ID=W.WAIT_FOR_ID;
排查数据库服务报错或阻塞问题时,可按以下步骤进行:
1、在A窗口执行报错 SQL;
2、在B窗口执行 select * from vtrxwait,获取当前事务等待的 wait_for_trx_id;
3、接着通过 select * from vsessions where trx_id = <wait_for_trx_id> 查找对应会话信息,提取 eid;
4、在 dpc.show_threads() 的结果中定位该 eid 所对应的线程,获取其操作系统线程号;
5、最后使用 pstack 线程号 保留信息。
整个过程中注意保留 vtrxwait、vsessions、dpc.show_threads() 输出和堆栈信息,便于问题复现和研发分析。
注:如果现场着急恢复业务,可直接将对应的bp主节点生成core文件,以便现场业务正常运转。kill -11 进程号
文章
阅读量
获赞