Oracle动态视图v$active_session_history怎么应用
导读:本文共2905.5字符,通常情况下阅读需要10分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 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... ...
目录
(为您整理了一些要点),点击可以直达。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;
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
Oracle动态视图v$active_session_history怎么应用的详细内容,希望对您有所帮助,信息来源于网络。