這篇文章將為大家詳細(xì)講解有關(guān)如何查看鎖定的session信息腳本,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
查看當(dāng)前被阻塞的對象和鎖信息
SELECT DISTINCT
s1.inst_id BlockingInst,
s1.sid BlockingSid,
s1.serial# BlockingSerial,
s2.inst_id BlockedInst,
s2.sid BlockedSid,
s2.username BlockedUser,
s2.seconds_in_wait BlockedWaitTime
FROM gv$session s1,
gv$lock l1,
gv$session s2,
gv$lock l2
WHERE s1.inst_id = l1.inst_id and
l1.block in (1, 2) and
l2.request != 0 and
l1.sid = s1.sid and
l1.id1 = l2.id1 and
l1.id2 = l2.id2 and
s2.sid = l2.sid and
s2.inst_id = l2.inst_id
ORDER BY 1, 2, 3
查看被鎖的回話信息:
SELECT
s.blocking_session,
s.sid,
s.osuser,
s.seconds_in_wait,
s.event,
s.state,
t.sql_text,
o.object_name
FROM
v$session s, v$sqltext t, v$locked_object lo, dba_objects o
WHERE
blocking_session IS NOT NULL
and t.hash_value=s.sql_hash_value
and s.sid=lo.session_id
and lo.object_id=o.object_id
ORDER BY t.hash_value,t.PIECE;
以DBA角色, 查看當(dāng)前數(shù)據(jù)庫里鎖的情況可以用如下SQL語句:
col owner for a12
col object_name for a16
select b.owner,b.object_name,l.session_id,l.locked_mode
from v$locked_object l, dba_objects b
where b.object_id=l.object_id
/
select t2.username,t2.sid,t2.serial#,t2.logon_time ,t1.object_id,t3.object_name,t1.locked_mode
from v$locked_object t1,v$session t2 ,dba_objects t3
where t1.session_id=t2.sid and t1.object_id=t3.object_id order by t2.logon_time
/
如果有長期出現(xiàn)的一列,可能是沒有釋放的鎖。我們可以用下面SQL語句殺掉長期沒有釋放非正常的鎖:
alter system kill session 'sid,serial#';
另外幾個可以查詢阻塞回話的視圖:
DBA_WAITERS
DBA_BLOCKERS
V$WAIT_CHAINS
關(guān)于“如何查看鎖定的session信息腳本”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。