查看等待事件
--v$session_wait视图中的p1、p2、p3表示等待事件的具体含义,如果Wait Event是db file scattered read,那么p1=file_id/p2=block_id/p3=blocks,然后通过dba_extents即可
确定出热点对象.
--如果是latch free的话,那么p2为闩锁号,它指向v$latch.
--求等待事件及其对应的latch
col event format a32;
col name format a32;
select sid,event,p1 as "p1 as file_id", p2 as "p2 as block_id/latch", p3 as "p3 as blocks",l.name
from v$session_wait sw,v$latch l
where event not like '%SQL%' and event not like '%rdbms%' and event not like '%mon%' and sw.p2 = l.latch#(+);
--求等待事件及其热点对象
col owner format a18;
col segment_name format a32;
col segment_type format a32;
select owner, segment_name, segment_type from dba_extents
where file_id = &file_id and &block_id between block_id and block_id + &blocks - 1;
--综合以上两条SQL,同时显示latch及热点对象(速度较慢)
select sw.sid, event, l.name, de.segment_name from v$session_wait sw, v$latch l, dba_extents de
where event not like '%SQL%' and event not like '%rdbms%' and event not like '%mon%'
and sw.p2 = l.latch#(+) and sw.p1 = de.file_id(+) and p2 between de.block_id and de.block_id + de.blocks - 1;
--如果是非空闲等待事件,通过等待会话的SID可以求出该会话在执行的SQL
select sql_text from v$sqltext_with_newlines st, v$session se
where st.address = se.sql_address and st.hash_value = se.sql_hash_value and se.sid = &wait_sid order by piece;