數據庫運行過程當中,當用戶業務操做產生I/O時,oracle數據庫會在相應的表上加鎖,來確保數據庫的一致性讀。可是當鎖長期不釋放時,可能存在數據庫故障。sql
此時咱們能夠關聯一些視圖,來檢查鎖定的表,應用程序鎖表的sql以及相關的等待事件,再結合awr報告就能夠發現數據庫故障。數據庫
--查詢鎖定的表(簡版)session
select t2.sid,oracle
t2.serial#,進程
t2.username,事件
t3.object_name,terminal
t1.locked_mode,it
t2.logon_timeio
from v$locked_object t1, v$session t2, dba_objects t3event
where t1.session_id = t2.sid
and t3.object_id = t1.object_id
order by t2.logon_time
--查詢鎖表的sql
select l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
d.object_name, /*s.user#,l.os_user_name,s.machine,s.terminal,a.action,*/
a.sql_text,
w.event--等待事件,須要特別關注一下
from v$sqlarea a, v$session s, v$locked_object l, dba_objects d,v$session_wait w
where l.session_id = s.sid
and s.prev_sql_addr = a.address
and l.object_id = d.object_id
and s.sid = w.sid
order by sid, s.serial#
--殺掉死鎖進程
alter system kill session 'sid,serial#'
--查看全部等待事件
select * from v$system_event order by total_waits desc