zoukankan      html  css  js  c++  java
  • rac中 kull session会话脚本

    方法:ALTER SYSTEM KILL SESSION '80, 6, @2';  --<= 80 sid,6 serial#,@2 inst_id

    kill session 脚本如下:
    select 'alter system kill session '''||a.sid||','||b.serial#||',@'||c.inst_id||''' immediate ;' from
    gv$session a ,gv$session b, gv$session c
    where a.username=b.username and c.sid=b.sid and a.serial#=c.serial#
    and a.username='DOUDOU'; --<=username可以换成你想kill的用户

    实验如下

    环境:11.2.0.4 rac on redhat6.3 

    1.在2个不同的node登录2个doudou用户

    [oracle@rac1 ~]$ sqlplus doudou/oracle

    SQL*Plus: Release 11.2.0.4.0 Production on Sun Aug 24 16:33:54 2014


    Copyright (c) 1982, 2013, Oracle.  All rights reserved.




    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options




    DBA                            TEL                    MAIL
    ------------------------------ ---------------------- --------------------
    oracle world of wenyu.he       18211103395            wenyu.he@bhaf.com.cn  <= edit glogin.sql 


    DOUDOU@doudou1>   <= doudou1 is rac1 instance




    [oracle@rac2 ~]$ sqlplus doudou/oracle


    SQL*Plus: Release 11.2.0.4.0 Production on Sun Aug 24 16:34:40 2014


    Copyright (c) 1982, 2013, Oracle.  All rights reserved.




    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options




    DBA                            TEL                    MAIL
    ------------------------------ ---------------------- --------------------
    oracle world of wenyu.he       18211103395            wenyu.he@bhaf.com.cn


    DOUDOU@doudou2>    <= doudou2 is rac2 instance




    2.使用脚本生成批量kill session的语句
    SYS@doudou1> select 'alter system kill session '''||a.sid||','||b.serial#||',@'||c.inst_id||''' immediate ;' from
      2  gv$session a ,gv$session b, gv$session c
      3  where a.username=b.username and c.sid=b.sid and a.serial#=c.serial#
      4  and a.username='DOUDOU';


    'ALTERSYSTEMKILLSESSION'''||A.SID||','||B.SERIAL#||',@'||C.INST_ID||'''IMMEDIATE
    --------------------------------------------------------------------------------
    alter system kill session '63,93,@1' immediate ;
    alter system kill session '57,33,@2' immediate ;


    3.执行kill session
    SYS@doudou1> alter system kill session '63,93,@1' immediate ;


    System altered.


    alert_doudou1.log如下:
    Immediate Kill Session#: 63, Serial#: 93
    Immediate Kill Session: sess: 0x763924c8  OS pid: 8806
    --从日志来看,session已经被kill


    SYS@doudou1> alter system kill session '57,33,@2' immediate ;


    System altered.


    alert_doudou2.log如下:
    Immediate Kill Session#: 57, Serial#: 33
    Immediate Kill Session: sess: 0x763a4a08  OS pid: 18221
    --从日志来看,session已经被kill


    4.验证session是否被kill掉
    脚本继续执行一次查看结果
    SYS@doudou1> select 'alter system kill session '''||a.sid||','||b.serial#||',@'||c.inst_id||''' immediate ;' from
      2  gv$session a ,gv$session b, gv$session c
    where a.username=b.username and c.sid=b.sid and a.serial#=c.serial#
      3    4  and a.username='DOUDOU';


    no rows selected
    --从脚本输出结果表示session已经被kill


    5.去节点实例看看当前session状态
    DOUDOU@doudou1> select * from tab;
    select * from tab
    *
    ERROR at line 1:
    ORA-03135: connection lost contact
    Process ID: 8806
    Session ID: 63 Serial number: 93


    DOUDOU@doudou2> select * from tab;   
    select * from tab
    *
    ERROR at line 1:
    ORA-03135: connection lost contact
    Process ID: 18221
    Session ID: 57 Serial number: 33
    --session 确实已经被kill




    总结:
    RAC中的管理方法会和单实例略有不同,多看官档。希望可以(稳、准、狠)的管理好我的“RAC群”

  • 相关阅读:
    C#网络编程之Http请求
    使用 pdf.js 在网页中加载 pdf 文件
    程序员转型技术管理,这几本书不能错过
    HTTPS小结 、TSL、SSL
    clipboard 在 vue 项目中,on 事件监听回调多次执行
    Vue 引入 .md 文件,解析markdown语法
    Vue cli4.0 代理配置
    npm publish 一直报错 404
    JSON 多层对象获取键值
    Tomcat8配置Https协议,Tomcat配置Https安全访问,Tomcat Https配置
  • 原文地址:https://www.cnblogs.com/travel6868/p/4949988.html
Copyright © 2011-2022 走看看