Oracle动态视图v$active_session_history怎么应用

免费教程   2024年05月09日 22:38  

这篇文章主要介绍“Oracle动态视图v$active_session_history怎么应用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Oracle动态视图v$active_session_history怎么应用”文章能帮助大家解决问题。

Oracle动态视图实战之v$active_session_history先看下官方解释

Samples of wait event information are taken once per second and made available using theV$ACTIVE_SESSION_HISTORYview. 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-0200:22至00:35,数据落盘慢,根据情况查看此时间段的主要活动事件,数量,与sql_id(全局)selectcount(*),sql_id,event,blocking_sessionfromgv$active_session_historywheresample_timebetweento_date('2023-03-0200:22:00','yyyy-mm-ddhh34:mi:ss')andto_date('2023-03-0200:35:00','yyyy-mm-ddhh34:mi:ss')groupbysql_id,event,blocking_sessionorderby1;(非全局)BLOCKING_INST_ID--被阻塞者,blocking_session--阻塞者selectcount(*),sql_id,event,BLOCKING_INST_ID,blocking_sessionfromv$active_session_historywheresample_timebetweento_date('2023-03-0200:20:00','yyyy-mm-ddhh34:mi:ss')andto_date('2023-03-0200:35:00','yyyy-mm-ddhh34:mi:ss')groupbysql_id,event,BLOCKING_INST_ID,blocking_sessionorderby1;b.现在我们已经得到两个关键信息:sql_id与阻塞事件,首先根据sql_id我们可以再进一步使用此视图,实际中可以多调整几个较小的时间段,以突出最有代表的信息selectcount(*),session_id,session_serial#,sql_id,event,BLOCKING_INST_ID,blocking_sessionfromv$active_session_historywheresample_timebetweento_date('2023-03-0200:24:00','yyyy-mm-ddhh34:mi:ss')andto_date('2023-03-0200:25:00','yyyy-mm-ddhh34:mi:ss')andsql_id='1xfbtdvu3xb67'groupbysession_id,session_serial#,sql_id,event,BLOCKING_INST_ID,blocking_sessionorderby3;c.加入等待事件后更清晰selectcount(*),session_id,sql_id,event,BLOCKING_INST_ID,blocking_sessionfromv$active_session_historywheresample_timebetweento_date('2023-03-0200:25:00','yyyy-mm-ddhh34:mi:ss')andto_date('2023-03-0200:35:00','yyyy-mm-ddhh34:mi:ss')andevent='librarycachelock'andsql_id='1j47z0mc6k02b'groupbysession_id,sql_id,event,BLOCKING_INST_ID,blocking_sessionorderby1;结论:可以看出大量并发等待,最终是发现有什么阻塞了此SQL语句结合我们的AWR报告

当然也要结合我们的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确定创建时间是否匹配selectowner,object_name,object_type,to_char(created,'yyyy-mm-ddhh34:mi:ss')fromdba_objectswhereobject_name='AA_BBB_CCCC_DDDD_OUT'andcreated>to_date('2023-03-01','yyyy-mm-dd')orderby4;selectowner,object_name,object_type,to_char(created,'yyyy-mm-ddhh34:mi:ss')fromdba_objectswhereobject_name='AA_BBB_CCCC_DDDD_IN'andcreated>to_date('2023-03-01','yyyy-mm-dd')orderby4;

关于“Oracle动态视图v$active_session_history怎么应用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注行业资讯频道,小编每天都会为大家更新不同的知识点。

域名注册
购买VPS主机

您或许对下面这些文章有兴趣:                    本月吐槽辛苦排行榜

看贴要回贴有N种理由!看帖不回贴的后果你懂得的!


评论内容 (*必填):
(Ctrl + Enter提交)   

部落快速搜索栏

各类专题梳理

网站导航栏

X
返回顶部