查看oracle锁表

查看处于被锁状态的表:v$locked_object dba_objects v$session all_objects v$sqlarea v$lock

--1.查看处于被锁状态的表
SELECT a.object_id,
       a.session_id,
       b.object_name
  FROM v$locked_object a,
       dba_objects     b
 WHERE a.object_id = b.object_id

--2.查出锁定object的session的信息以及被锁定的object名
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#;
--2.1查出锁定的object的session信息(指定object_name)
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
   and o.object_name = 'ZZOM_SEND_EMAIL'
 ORDER BY sid, s.serial#;
--3.查出锁定表的session的sid, serial#,os_user_name, machine name, terminal和执行的语句
--比上面那段多出sql_text和action
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#;

--4.查出锁定表的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;


你可能感兴趣的:(oracle,锁表)