Home > Database > Mysql Tutorial > Oracle 用存储过程杀掉session解决锁表的问题

Oracle 用存储过程杀掉session解决锁表的问题

WBOY
Release: 2016-06-07 17:33:40
Original
1678 people have browsed it

锁表,相信大家都遇到过,解锁的方法想必大家也都知道,但是一个个的杀进程难免有些低级,我们用存储过程来实现这一功能,就变得

锁表,相信大家都遇到过,解锁的方法想必大家也都知道,但是一个个的杀进程难免有些低级,,我们用存储过程来实现这一功能,就变得异常简单了。

1.建立视图,查询进程信息,注意要给当前用户赋予系统权限select any dictionary

create or replace view mysession as
select b.sid,b.serial# from v$lock a,v$session b where a.SID = b.SID and status='INACTIVE'
--and program'plsqldev.exe' 
order by machine;

2.创建存储过程,循环上边试图中的数据,一一kill,注意需要当前用户赋予系统权限alter system

create or replace procedure kill_session is
  v_sid    varchar2(30);
  v_serial varchar2(30);
  v_sql    varchar2(1000);
  TYPE DyData IS REF CURSOR;
  rows DyData;
begin

  v_sql := 'select * from mysession ';
  OPEN rows FOR v_sql;
  LOOP
    FETCH rows
      into v_sid, v_serial;
 
    v_sql := 'alter system kill session ''' || v_sid || ',' || v_serial || '''';
    execute immediate v_sql;
    --dbms_output.put_line(v_userid || '__' || v_user || '__' || v_pwd);
 
    EXIT WHEN rows%NOTFOUND;
  END LOOP;

end kill_session;

3.执行存储过程

begin
  -- Call the procedure
  kill_session;
end;

注意有时候可能会把自己的进程也杀掉,只需要自己修改一下第一步的视图,把自己排除即可。

相关阅读:

Oracle 10 DBMS_MONITOR跟踪和分析其它session SQL 

快速找到跟踪其他session产生的trc文件 

Oracle 彻底 kill session 

MySQL主从故障处理--session 级别参数复制错误

如何查看Oracle数据库的session阻塞 

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template