Oracle解決鎖表語句與批量生成解鎖語句

--如下幾個爲相關表
SELECT * FROM v$lock;
SELECT * FROM v$sqlarea;
SELECT * FROM v$session;
SELECT * FROM v$process ;
SELECT * FROM v$locked_object;
SELECT * FROM all_objects;
SELECT * FROM v$session_wait;sql

--查看被鎖的表 
select b.owner,b.object_name,a.session_id,a.locked_mode from v$locked_object a,dba_objects b where b.object_id = a.object_id;數據庫

--查看那個用戶那個進程照成死鎖
select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = b.sid order by b.logon_time;session

--查看鏈接的進程 
SELECT sid, serial#, username, osuser FROM v$session;進程

--查出鎖定表的sid, serial#,os_user_name, machine_name, terminal,鎖的type,mode
SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,
s.terminal, s.logon_time, l.type
FROM v$session s, v$lock l
WHERE s.sid = l.sid
AND s.username IS NOT NULL
ORDER BY sid;terminal

這個語句將查找到數據庫中全部的DML語句產生的鎖,還能夠發現,
任何DML語句其實產生了兩個鎖,一個是表鎖,一個是行鎖。it

--殺掉進程 sid,serial#
alter system kill session'210,11562';io

--批量解鎖語句生成object

select a.object_name,b.session_id,c.serial#,'alter system kill session '''||b.session_id||','||c.serial#||'''; ' as a,c.program,c.username,c.command,c.machine,c.lockwait
from all_objects a,v$locked_object b,v$session c where a.object_id=b.object_id and c.sid=b.session_id;

select

相關文章
相關標籤/搜索