rac中 kull session会话脚本
2015-11-09 15:07
197 查看
方法: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群”
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群”
相关文章推荐
- 简单几何(圆与多边形公共面积) UVALive 7072 Signal Interference (14广州D)
- 通过QT 转换html文件为word文档
- js#0基本概念
- android-Hander的用法大全
- Go学习笔记:interface
- [故障及解决]SoundPool没有声音
- android 蓝牙BLE多连接
- 模块化架构之tomcat的jsp加载处理
- C++调用matlab计算
- MR实现--矩阵乘法
- linux MySql问题Access denied for user 'root'@'localhost' (using password:YES)
- c# webclient下载网页
- rabbitMq入门,整合spring
- UITableView左滑出现多个按钮
- UITableView 类似通讯录的索引
- 禁止uiscrollview垂直方向滚动,只允许水平方向滚动;或只允许垂直方向滚动
- 感悟现实人生真谛
- oracle session 相关优化
- 配置微信公众号使用js-sdk
- 文本处理命令系列――uniq