ASH裸数据dba_hist_active_sess_history的分析
因为最近故障处理经常会用到这类查询进行ASH裸数据的分析,下面以m_ash0902为命名,时间为:2019-09-02 16:00:00 -> 2019-09-02 18:00:00,方便根据实际情况直接进行批量替换。
将客户的awrdump导入到自己测试环境后,可以直接通过dba_hist_active_sess_history查询,但推荐还是新建一张表专门存放相关数据,表名以m_ash<日期>命名
1 | create table m_ash0902 tablespace dbs_d_awr as select * from dba_hist_active_sess_history where dbid = &dbid; |
注:以下脚本原创作者:Maclean Liu
- 1.确定异常时刻的top n event
- 2.确定最终的top holder
- 3.找出每个采样点的最终top holder
1.确定异常时刻的top n event
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | --1.确定异常时刻的top n event select t.dbid, t.sample_id, t.sample_time, t.instance_number, t.event, t.session_state, t.c session_count from ( select t.*, rank() over(partition by dbid, instance_number, sample_time order by c desc ) r from ( select /*+ parallel 8 */ t.*, count (*) over(partition by dbid, instance_number, sample_time, event) c, row_number() over(partition by dbid, instance_number, sample_time, event order by 1) r1 from m_ash0902 t where sample_time > to_timestamp( '2019-09-02 16:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) and sample_time < to_timestamp( '2019-09-02 18:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) ) t where r1 = 1) t where r < 3 order by dbid, instance_number, sample_time, r; |
2.确定最终的top holder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | --2.确定最终的top holder select level lv, connect_by_isleaf isleaf, connect_by_iscycle iscycle, t.dbid, t.sample_id, t.sample_time, t.instance_number, t.session_id, t.sql_id, t.session_type, t.event, t.session_state, t.blocking_inst_id, t.blocking_session, t.blocking_session_status from m_ash0902 t where sample_time > to_timestamp( '2019-09-02 16:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) and sample_time < to_timestamp( '2019-09-02 18:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) start with blocking_session is not null connect by nocycle prior dbid = dbid and prior sample_time = sample_time /*and ((prior sample_time) - sample_time between interval '-1' second and interval '1' second)*/ and prior blocking_inst_id = instance_number and prior blocking_session = session_id and prior blocking_session_serial# = session_serial# order siblings by dbid, sample_time; |
3.找出每个采样点的最终top holder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | --3.基于上一步的原理来找出每个采样点的最终top holder: select t.lv, t.iscycle, t.dbid, t.sample_id, t.sample_time, t.instance_number, t.session_id, t.sql_id, t.session_type, t.event, t.seq#, t.session_state, t.blocking_inst_id, t.blocking_session, t.blocking_session_status, t.c blocking_session_count from ( select t.*, row_number() over(partition by dbid, instance_number, sample_time order by c desc ) r from ( select t.*, count (*) over(partition by dbid, instance_number, sample_time, session_id) c, row_number() over(partition by dbid, instance_number, sample_time, session_id order by 1) r1 from ( select /*+ parallel 8 */ level lv, connect_by_isleaf isleaf, connect_by_iscycle iscycle, t.* from m_ash0902 t where sample_time > to_timestamp( '2019-09-02 16:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) and sample_time < to_timestamp( '2019-09-02 18:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) start with blocking_session is not null connect by nocycle prior dbid = dbid and prior sample_time = sample_time /*and ((prior sample_time) - sample_time between interval '-1' second and interval '1' second)*/ and prior blocking_inst_id = instance_number and prior blocking_session = session_id and prior blocking_session_serial# = session_serial#) t where t.isleaf = 1) t where r1 = 1) t where r < 3 order by dbid, sample_time, r; |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!