批量杀锁
select 'alter system kill session ''' || sid || ',' || serial# || ',@' ||
inst_id || ''' immediate;'
from gv$session
where (sid, inst_id) in
(select blocking_session, blocking_instance
from gv$session
where blocking_session is not null)
and type = 'USER';
查看等待用户
set linesize 300
col WAITING_SQL for a50
select w.waiting_session,
s2.username waiting_user,
q2.sql_text waiting_sql
from dba_waiters w,
v$session s2,
v$sqlarea q2
where w.waiting_session = s2.sid
and s2.sql_address = q2.address;
查看锁源
col sid for 999999999999
col user_name for a15
col OBJECT_NAME for a30
select /*+ rule */ lpad('--',decode(b.block,1,0,4))||s.username user_name,
b.type,o.owner||'.'||o.object_name object_name,
s.sid,s.serial#,decode(b.request,0,'BLOCKED','WAITING') status
from dba_objects o, v$session s, v$lock v,v$lock b
where v.id1=o.object_id and v.sid=s.sid
and v.sid=b.sid and (b.block=1 or b.request>0)
and v.type='TM'
order by b.id2,v.id1,user_name desc;
操作系统层面杀锁
select ss.inst_id, 'kill -9 ' || ss.process os_kill_session from gv$session s,gv$session ss where s.final_blocking_session is not null and s.final_blocking_instance = ss.inst_id and s.final_blocking_session = ss.sid and s.sid <> ss.sid;
查看历史锁信息
select instance_number,session_id,sql_id,machine,event,BLOCKING_INST_ID,blocking_session,to_char(sample_time,'yyyy-MM-dd HH24:mi:ss') from DBA_HIST_ACTIVE_SESS_HISTORY where sample_time>to_date('2019-11-22 17:00:00','yyyy-MM-dd HH24:mi:ss') and sample_time<to_date('2019-11-22 18:00:00','yyyy-MM-dd HH24:mi:ss') and wait_class<>'Idle' and event='enq: TX - row lock contention';