如何查询导致oracle阻塞的具体sql语句
程总,请教个问题:oracle遇到 tx锁的情况,要查询出具体是那条sql导致的锁,从而阻塞了其他sql语句的正常执行。
例如: 下面这中方式,只能查询到时 157 sid执行的sql导致了阻塞,但是查询不到是那条sql由于未提交导致的tx锁,从而阻塞了其他sql的正常执行,现在想查询出具体的sql,请问有什么方法?谢谢。
session1;
create table t_all_objs as select owner,object_id,object_name from all_objects where 0=1;
alter table T_ALL_OBJSadd constraint pk_t_all_objs primary key (OBJECT_ID);
insert into t_all_objs(owner,object_id,object_name) values('TEST',2013011701,'test1');
insert into t_all_objs(owner,object_id,object_name) values('TEST',2013011702,'test2');
commit;
update t_all_objs set object_name='test11' where object_id=2013011701;
select sid from v$mystat where rownum=1;--157
session 2
SQL> select sid from v$mystat where rownum=1;
SID
----------
273
SQL> update stz.t_all_objs set object_name='test101' where object_id=2013011701;
会一直等待.
session 3
SQL>select sid from v$mystat where rownum=1;
SID
----------
419
SQL>update stz.t_all_objs set object_name='test101419' where object_id=2013011701;
也会一直等待。
session4;
SELECT 'blocker('
|| wb.holding_session
|| ':'
|| sb.username
|| ')-sql:'
|| qb.sql_text
blockers,
'waiter ('
|| wb.waiting_session
|| ':'
|| sw.username
|| ')-sql:'
|| qw.sql_text
waiters
FROM dba_waiters wb,
v$session sb,
v$session sw,
v$sqlarea qb,
v$sqlarea qw
WHERE wb.holding_session = sb.sid
AND wb.waiting_session = sw.sid
AND sb.prev_sql_addr = qb.address
AND sw.sql_address = qw.address
AND wb.mode_held <> 'None';
blocker(157:stz)-sql:select sid from v$mystat where rownum=1 waiter (419:SYS)-sql: update stz.t_all_objs set object_name='test101419' where object_id=2013011701
blocker(157:stz)-sql:select sid from v$mystat where rownum=1 waiter (273:SYS)-sql:update stz.t_all_objs set object_name='test101' where object_id=2013011701
现在只能查询到 sid 为157的session的sql 为:执行完update之后 执行的sql语句select sid from v$mystat where rownum=1。可以通过什么方式查询到 sid为157 执行的 未提叫的sql语句(update t_all_objs set object_name='test11' where object_id=2013011701)呢?谢谢。
你这样的情况,可以找出来阻塞的sid,然后通过v$open_cursor去找这个session里面语句,如果运气好可以找到,如果这个里面也没有了,那从现场来说,不容易找出来 好的,多谢
页:
[1]