View the lock table status and processing method in the current system in ORACLE

1. View the lock table status in the current system in ORACLE
select * from v$locked_object 
You can get the sid and objectid by querying v$locked_object, and then use the sid and v$session linked list to query where the locked table is, use the v$session in the The objectid field is associated with the id field of dba_objects to query the detailed lock table status.

查询SQL如下:
select sess.sid,
       sess.serial#,
       lo.oracle_username,
       lo.os_user_name,
       ao.object_name,
       lo.locked_mode
  from v$locked_object lo, dba_objects ao, v$session sess, v$process p
where ao.object_id = lo.object_id
   and lo.session_id = sess.sid;

查询是什么SQL引起了锁表的原因,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#;

2. ORACLE unlock method
alter system kill session '146'; –146 is the locked process number, that is, spid

 

select 'alter system kill session ' || '''' || t2.sid || ','|| t2.serial# || '''' ||';' , t2.username,t2.sid,t2.serial#,t2.logon_time from v$locked_object t1,V$session t2 where t1.SESSION_ID=t2.SID;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326989339&siteId=291194637