Oracle查锁表

Oracle查锁表

  • 一、Oracle DDL锁的解锁
    • 1.1、查表的DDL锁
    • 1.2、根据session_id找SID,SERIAL#
    • 1.3、杀会话kill session
  • 二、Oracle DML锁的解锁
    • 2.1、查表的DML锁
    • 2.2、根据session_id找SID,SERIAL#
    • 2.3、杀会话kill session
  • 三、附录
    • 3.1、根据sid查sql_text


一、Oracle DDL锁的解锁

Oracle分两种锁,一种是DDL锁,一种是DML锁。

1.1、查表的DDL锁

查DDL锁的数据字典,SQL如下:

select * from dba_ddl_locks
 WHERE owner = 'TZQ'
   AND NAME LIKE '%TZQ_LOG_T%'

1.2、根据session_id找SID,SERIAL#

根据session_id找SID,SERIAL#,SQL如下:

select s.INST_ID,s.SID,s.SERIAL# 
  from gv$session s 
 where 1=1
   -- AND s.INST_ID =1 
   and s.SID IN (6335);

1.3、杀会话kill session

打开命令行窗口,执行下面命令:

AUTO_SERVER_PKG
execute sys.auto_server_pkg.kill_session(6335,15519);

二、Oracle DML锁的解锁

Oracle分两种锁,一种是DDL锁,一种是DML锁。

2.1、查表的DML锁

查DML锁的数据字典,SQL如下:

select /*DISTINCT '''' || s.sid || ',' || s.serial# || ',@' ||
                      s.INST_ID || '''' AS si_id*/
       *
  from gv$locked_object l, dba_objects o, gv$session s
 where l.object_id = o.object_id
   and l.session_id = s.sid
   and l.inst_id = s.inst_id
   and o.owner = upper('TZQ')
   and o.object_name = upper('TZQ_LOG_T');

2.2、根据session_id找SID,SERIAL#

根据session_id找SID,SERIAL#,SQL如下:

select s.INST_ID,s.SID,s.SERIAL# 
  from gv$session s 
 where 1=1
   -- AND s.INST_ID =1 
   and s.SID IN (6335);

2.3、杀会话kill session

打开命令行窗口,执行下面命令:

AUTO_SERVER_PKG
execute sys.auto_server_pkg.kill_session(6335,15519);

三、附录

3.1、根据sid查sql_text

SELECT s.sid
      ,s.serial#
      ,s.sql_id
      ,s.sql_hash_value
      ,s.username
      ,a.sql_text
  FROM gv$session s
  LEFT JOIN v$sqlarea a
    ON s.sql_id = a.sql_id
 WHERE s.sql_id IS NOT NULL;

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