ORACLE尋找並解除死結進程
1、尋找死結進程
select /*+RULE*/v$lock.sid,
decode(v$lock.type,
'MR', 'Media Recovery',
'RT','Redo Thread',
'UN','User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distributed Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalida-tion',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
'Unknown') LockType,
rtrim(object_type) || ' ' || rtrim(owner) || '.' || object_name object_name,
decode(lmode, 0, 'None',
1, 'Null',
2, 'Row-S',
3, 'Row-X',
4, 'Share',
5, 'S/Row-X',
6, 'Exclusive', 'Unknown') LockMode,
decode(request, 0, 'None',
1, 'Null',
2, 'Row-S',
3, 'Row-X',
4, 'Share',
5, 'S/Row-X',
6, 'Exclusive', 'Unknown') RequestMode,
ctime, block b
from v$lock, all_objects
where sid > 8
and v$lock.id1 = all_objects.object_id
如果查詢結果有記錄表明有鎖
2、這個SQL可用來產生殺死死結進程的SQL
select /*+RULE*/
'alter system kill session ''' || a.sid || ',' || b.serial# || ''';'
from v$lock a, all_objects c, v$session b
where a.sid > 8
and a.id1 = c.object_id
and a.sid = b.sid;
或
select /*+RULE*/
'alter system kill session ''' || a.sid || ',' || b.serial# || ''';'
from v$lock a, v$session b
where a.sid > 8
and a.sid = b.sid;
3、把第二步的查詢結果匯出為指令碼,在SQLPLUS中執行該指令碼即可解除死結。