select se.sid,s.username,se.event,se.total_waits,se.time_waited,se.average_wait from v$session s,v$session_event se where s.sid = se.sid and se.event not like 'SQL*Net%' and s.status = 'ACTIVE' and s.username is not null; 3)使用下面查询找到与所连接的会话有关的当前等待事件。这些信息是动态的,为了查看一个会话的等待最多的事件是什么,需要多次执行此查询。
select sw.sid,s.username,sw.event,sw.wait_time,sw.state,sw.seconds_in_wait SEC_IN_WAIT from v$session s,v$session_wait sw where s.sid = sw.sid and sw.event not like 'SQL*Net%' and s.username is not null order by sw.wait_time desc; 4)查询会话等待事件的详细信息
select sid,event,p1text,p1,p2text,p2,p3text,p3 from v$session_wait where sid between &1 and &2 and event not like '%SQL%' and event not like '%rdbms%'; 5)利用P1、P2的信息,找出等待事件的相关的段
select owner,segment_name,segment_type,tablespace_name from dba_extents where file_id = &fileid_in and &blockid_in between block_id and block_id + blocks - 1; 6)获得操作该段的sql语句:
select sid, getsqltxt(sql_hash_value,sql_address) from v$session where sid = &sid_in; 7)getsqltxt函数
alter session set timed_statistics=true; alter session set max_dump_file_size=unlimited; alter session set events '10046 trace name context forever, level 12';
2)执行应用程序,然后在USER_DUMP_DEST指出的目录中找到跟踪文件。
3)查看文件中以词WAIT开始的所有行。
4)对于其它的会话
5)确定会话的进程ID(SPID)。下面的查询识别出名称以A开始的所有用户的会话进程ID:
select S.Username, P.Spid from V$SESSION S, V$PROCESS P where S.PADDR = P.ADDR and S.Username like 'A%';
6)以sysdba进入sqlplus执行
alter session set timed_statistics=true; alter session set max_dump_file_size=unlimited; oradebug setospid oradebug unlimit oradebug event 10046 trace name context forever, level X /* Where X = (1,4,8,12) */