检测数据库各实例session 阻塞 tree的sql
2016-03-22 13:32
441 查看
DBA的日常功能SQL之一,绝对原创。
由于使用到了 v$sesion 的 blocking_instance,blocking_session 这两列,所以数据库的最低版本为oracle 10g。
适合单实例和多实实例数据库,一个SQL搞定。
with/*+ materialized +*/ aa as (
select *
from gv$session s
where 1=1
)
select
'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
lpad('+', 2 * level - 1) ||t.inst_sid as leveL_inst_sid,
level level_flag,
sys_connect_by_path(t.inst_sid,'/') as inst_sid_path,
connect_by_root t.inst_sid as root_inst_sid,
connect_by_isleaf as node_isleaf,
'##########' as FLAGFLAG0,
t.status,
t.event#,
t.event,
t.program,
t.module,
t.action,
t.client_identifier,
t.OSUSER os_USER,
t.machine os_machine,
t.logon_time logon_time,
t.last_call_et last_call_et,
'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
'##########' as FLAGFLAG/*,
t.* */
from (
select gs.inst_id||'-'||gs.sid as inst_sid,
gs.blocking_instance||'-'||gs.blocking_session par_inst_sid,
gs.*
from aa gs
where 1=1
and (gs.inst_id,gs.sid ) in (
--被阻塞者
select s.inst_id,s.sid
from aa s
where 1=1
and s.BLOCKING_SESSION is not null
union all
--阻塞者
select sw.inst_id,sw.sid
from aa sw
where 1=1
--and lower(sw.MACHINE) not like '%ejb%'
and (sw.INST_ID,sw.SID) in (
select/*+ hash_sj*/
s.BLOCKING_INSTANCE,
s.BLOCKING_SESSION
from aa s
where 1=1
and s.BLOCKING_SESSION is not null
)
)
) t
where 1=1
connect by prior t.inst_sid =t.par_inst_sid
order siblings by t.inst_sid
;
由于使用到了 v$sesion 的 blocking_instance,blocking_session 这两列,所以数据库的最低版本为oracle 10g。
适合单实例和多实实例数据库,一个SQL搞定。
with/*+ materialized +*/ aa as (
select *
from gv$session s
where 1=1
)
select
'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
lpad('+', 2 * level - 1) ||t.inst_sid as leveL_inst_sid,
level level_flag,
sys_connect_by_path(t.inst_sid,'/') as inst_sid_path,
connect_by_root t.inst_sid as root_inst_sid,
connect_by_isleaf as node_isleaf,
'##########' as FLAGFLAG0,
t.status,
t.event#,
t.event,
t.program,
t.module,
t.action,
t.client_identifier,
t.OSUSER os_USER,
t.machine os_machine,
t.logon_time logon_time,
t.last_call_et last_call_et,
'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
'##########' as FLAGFLAG/*,
t.* */
from (
select gs.inst_id||'-'||gs.sid as inst_sid,
gs.blocking_instance||'-'||gs.blocking_session par_inst_sid,
gs.*
from aa gs
where 1=1
and (gs.inst_id,gs.sid ) in (
--被阻塞者
select s.inst_id,s.sid
from aa s
where 1=1
and s.BLOCKING_SESSION is not null
union all
--阻塞者
select sw.inst_id,sw.sid
from aa sw
where 1=1
--and lower(sw.MACHINE) not like '%ejb%'
and (sw.INST_ID,sw.SID) in (
select/*+ hash_sj*/
s.BLOCKING_INSTANCE,
s.BLOCKING_SESSION
from aa s
where 1=1
and s.BLOCKING_SESSION is not null
)
)
) t
where 1=1
connect by prior t.inst_sid =t.par_inst_sid
order siblings by t.inst_sid
;
相关文章推荐
- 【redis】跟着redis tutorial的基本学习
- Mysql服务器如何得到最佳性能优化
- mysql审计插件(运维不在背锅)
- 1.1-NoSQL的总体介绍
- 第三十二讲--数据库的关闭和启动
- oracle 修改用户名
- 第三十三讲--参数文件及数据库的启动和关闭详解
- Mysql数据库常用引擎的介绍
- MySql数据库事务的4大特性
- Sqlite3的使用
- MS SQL查询所有表行数,获取所有数据库名,表名,字段名
- 互联网架构设计之Redis篇-【Redis Windows版本安装过程】
- 互联网架构设计之Redis篇-【Redis的概述】
- service redis does not support chkconfig的解决办法
- 数据库建表原则
- MySQL排序原理与案例分析
- SQL STUFF函数 拼接字符串
- Oracle数据库的锁类型
- 第二十七讲--Oracle IMU及Redo Private Strands技术
- redisTemplate keys方法 为空