Oracle用户查找死锁进程

来源:互联网 发布:手机淘宝安卓版下载 编辑:程序博客网 时间:2024/05/07 04:03

Oracle用户查找死锁进程的SQL:

select s.SID, s.SERIAL#,
decode(t.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(a.object_type) || ' ' || rtrim(a.owner) || '.' || a.object_name object_name,
decode(t.lmode,   0, 'None',
                1, 'Null',
                2, 'Row-S',
                3, 'Row-X',
                4, 'Share',
                5, 'S/Row-X',
                6, 'Exclusive',       
                   'Unknown') LockMode,
decode(t.request, 0, 'None',
                1, 'Null',
                2, 'Row-S',
                3, 'Row-X',
                4, 'Share',
                5, 'S/Row-X',
                6, 'Exclusive',
                   'Unknown') RequestMode,
s.MACHINE, s.MODULE
from v$lock t, all_objects a, v$session s
where t.sid > 6
and t.id1 = a.object_id
and t.SID = s.sid

这个SQL可用来生成杀死死锁进程的SQL:

select 'alter system kill session '''||a.sid||','||b.serial#||''';'
from v$lock a,all_objects c,v$session b
where a.sid > 6 and a.id1 = c.object_id and a.sid = b.sid;