您好,登錄后才能下訂單哦!
背景:數據庫出現死鎖會話飆升的情況通過下列預計可以快速定位常見的鎖,快速干預處理,恢復數據庫性能。通過下列語句長期運維?T以上數據庫?個,屢試不爽。
一、查詢出死鎖的SID等信息
SELECT l.session_id sid,s.serial#,l.locked_mode,l.oracle_username,l.os_user_name,
s.machine,s.terminal,o.object_name,s.logon_time
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id AND l.session_id = s.sid
ORDER BY sid, s.serial#;
二、根據SID定位阻塞語句
SELECT /+ PUSH_SUBQ /
Command_Type, Sql_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts,Version_Count, Loaded_Versions, Open_Versions, Users_Opening, Executions,Users_Executing, Loads, First_Load_Time, Invalidations, Parse_Calls,Disk_Reads, Buffer_Gets, Rows_Processed, SYSDATE Start_Time,
SYSDATE Finish_Time, '>' || Address Sql_Address, 'N' Status
FROM V$sqlarea
WHERE Address = (SELECT Sql_Address FROM V$session WHERE Sid = ? );
三、殺死鎖
--殺死鎖(數據庫層次--適合不太緊急場合)
select 'alter system kill session '||chr(39)||t2.sid||','||t2.serial#||chr(39)||'immediate;'
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid order by t2.logon_time
--殺死鎖(操作系統層次--適合緊急場合)
select 'kill -9 '||t3.spid
from v$locked_object t1,v$session t2 , v$process t3
where t1.session_id=t2.sid And t2.paddr = t3.addr order by t2.logon_time
附日常會話查詢語句:
--所有會話信息
Select From v$session
Select Count() From v$session
--會話關鍵信息
Select USERNAME,status,state,MACHINE,logon_time From V$SESSION Order By username,MACHINE
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。