这篇文章主要介绍“Oracle动态视图v$active_session_history怎么应用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Oracle动态视图v$active_session_history怎么应用”文章能帮助大家解决问题。
Samples of wait event information are taken once per second and made available using the V$ACTIVE_SESSION_HISTORY view. An active session is one that is waiting on CPU or any event that does not belong to the "Idle" wait class at the time of the sample. The sample information is written to a circular buffer in the SGA, so the greater the database activity, the less time the information will remain available for.
有几个关键点:1秒采集一次,执行时间很快远小于1秒的SQL基本不会采集到,只写入非空闲状态的事件,循环存放活动越多保存的时间就越短。
v$active_session_history的字段非常丰富,实际工作中主要应用在下面这些情况:
a.应用场景:开发反应2023-03-02 00:22至00:35,数据落盘慢,根据情况查看此时间段的主要活动事件,数量,与sql_id(全局) select count(*), sql_id, event, blocking_session from gv$active_session_history where sample_time between to_date('2023-03-02 00:22:00', 'yyyy-mm-dd hh34:mi:ss') and to_date('2023-03-02 00:35:00', 'yyyy-mm-dd hh34:mi:ss') group by sql_id, event, blocking_session order by 1; (非全局)BLOCKING_INST_ID--被阻塞者, blocking_session--阻塞者 select count(*), sql_id, event, BLOCKING_INST_ID, blocking_session from v$active_session_history where sample_time between to_date('2023-03-02 00:20:00', 'yyyy-mm-dd hh34:mi:ss') and to_date('2023-03-02 00:35:00', 'yyyy-mm-dd hh34:mi:ss') group by sql_id, event, BLOCKING_INST_ID, blocking_session order by 1; b.现在我们已经得到两个关键信息:sql_id与阻塞事件,首先根据sql_id我们可以再进一步使用此视图,实际中可以多调整几个较小的时间段,以突出最有代表的信息 select count(*), session_id, session_serial#, sql_id, event, BLOCKING_INST_ID, blocking_session from v$active_session_history where sample_time between to_date('2023-03-02 00:24:00', 'yyyy-mm-dd hh34:mi:ss') and to_date('2023-03-02 00:25:00', 'yyyy-mm-dd hh34:mi:ss') and sql_id = '1xfbtdvu3xb67' group by session_id, session_serial#, sql_id, event, BLOCKING_INST_ID, blocking_session order by 3; c.加入等待事件后更清晰 select count(*), session_id, sql_id, event, BLOCKING_INST_ID, blocking_session from v$active_session_history where sample_time between to_date('2023-03-02 00:25:00', 'yyyy-mm-dd hh34:mi:ss') and to_date('2023-03-02 00:35:00', 'yyyy-mm-dd hh34:mi:ss') and event = 'library cache lock' and sql_id = '1j47z0mc6k02b' group by session_id, sql_id, event, BLOCKING_INST_ID, blocking_session order by 1; 结论:可以看出大量并发等待,最终是发现有什么阻塞了此SQL语句
当然也要结合我们的AWR报告:(两份为同时间段,上一份为有争用,下一份为正常情况,报告太长,只截取了关键点)
最后关键点a:下面报告里的sql_id与事件与v$active_session_history里查出来的结果相同,进一步证明事件与此SQL的关联性。
总结时间:
我们根据SQL_ID找到相应的SQL语句,从而找到对应的TABLE,最终对应到两张分区表,分别为:AA_BBB_CCCC_DDDD_OUT,AA_BBB_CCCC_DDDD_IN。
#根据dba_objects确定创建时间是否匹配 select owner, object_name, object_type, to_char(created, 'yyyy-mm-dd hh34:mi:ss') from dba_objects where object_name = 'AA_BBB_CCCC_DDDD_OUT' and created > to_date('2023-03-01', 'yyyy-mm-dd') order by 4; select owner, object_name, object_type, to_char(created, 'yyyy-mm-dd hh34:mi:ss') from dba_objects where object_name = 'AA_BBB_CCCC_DDDD_IN' and created > to_date('2023-03-01', 'yyyy-mm-dd') order by 4;
关于“Oracle动态视图v$active_session_history怎么应用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。