oracle运维--锁表查询统计

一.查询oralce用户锁表对象;

1.1 查询oracle用户名,机器名,锁表对象

select l.session_id sid,
      s.serial#,
      l.locked_mode,
      l.oracle_username,
      l.os_user_name,
      s.machine,
      s.terminal,
      o.object_name,
      s.logon_time
 from v$locked_object l, all_objects o, v$session s
where l.object_id = o.object_id
  and l.session_id = s.sid
       order by sid, s.serial#;

----通过sid会话查询sql语句;
select b.sql_text
 from v$session a, v$sql b
where a.sid = 955 --session_id
         and a.SQL_ADDRESS = b.ADDRESS(+);

1.2 查询导致锁表的SQL语句

select l.session_id sid,
      s.serial#,
      l.locked_mode,
      l.oracle_username,
      s.user#,
      l.os_user_name,
      s.machine,
      s.terminal,
      a.sql_text,
      a.action
 from v$sqlarea a, v$session s, v$locked_object l
where l.session_id = s.sid
  and s.prev_sql_addr = a.address
order by sid, s.serial#;

1.3 锁表信息统计;

select count(*) from v$locked_object;
select * from v$locked_object;

1.4 查看哪个表被锁;

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;

1.5 查看哪个session引起的锁表;

select b.username, b.sid, b.serial#, b.logon_time
 from v$locked_object a, v$session b
where a.session_id = b.sid
       order by b.logon_time;
       
------ kill掉锁表进程;
SID:955,SERIAL#:64087
alter system kill session '955,64087';

1.6 当前等待锁的所有会话;

select * from dba_waiters;

你可能感兴趣的:(oracle,运维)