溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

發(fā)布時(shí)間:2023-03-09 10:04:06 來(lái)源:億速云 閱讀:113 作者:iii 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要介紹“Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用”文章能幫助大家解決問(wèn)題。

Oracle動(dòng)態(tài)視圖實(shí)戰(zhàn)之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.

  • 有幾個(gè)關(guān)鍵點(diǎn):1秒采集一次,執(zhí)行時(shí)間很快遠(yuǎn)小于1秒的SQL基本不會(huì)采集到,只寫(xiě)入非空閑狀態(tài)的事件,循環(huán)存放活動(dòng)越多保存的時(shí)間就越短。

實(shí)際工作中主要應(yīng)用

v$active_session_history的字段非常豐富,實(shí)際工作中主要應(yīng)用在下面這些情況:

a.應(yīng)用場(chǎng)景:開(kāi)發(fā)反應(yīng)2023-03-02 00:22至00:35,數(shù)據(jù)落盤(pán)慢,根據(jù)情況查看此時(shí)間段的主要活動(dòng)事件,數(shù)量,與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.現(xiàn)在我們已經(jīng)得到兩個(gè)關(guān)鍵信息:sql_id與阻塞事件,首先根據(jù)sql_id我們可以再進(jìn)一步使用此視圖,實(shí)際中可以多調(diào)整幾個(gè)較小的時(shí)間段,以突出最有代表的信息
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;
結(jié)論:可以看出大量并發(fā)等待,最終是發(fā)現(xiàn)有什么阻塞了此SQL語(yǔ)句

結(jié)合我們的AWR報(bào)告

當(dāng)然也要結(jié)合我們的AWR報(bào)告:(兩份為同時(shí)間段,上一份為有爭(zhēng)用,下一份為正常情況,報(bào)告太長(zhǎng),只截取了關(guān)鍵點(diǎn))

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

關(guān)鍵點(diǎn)

最后關(guān)鍵點(diǎn)a:下面報(bào)告里的sql_id與事件與v$active_session_history里查出來(lái)的結(jié)果相同,進(jìn)一步證明事件與此SQL的關(guān)聯(lián)性。

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用

  • 總結(jié)時(shí)間:

我們根據(jù)SQL_ID找到相應(yīng)的SQL語(yǔ)句,從而找到對(duì)應(yīng)的TABLE,最終對(duì)應(yīng)到兩張分區(qū)表,分別為:AA_BBB_CCCC_DDDD_OUT,AA_BBB_CCCC_DDDD_IN。

#根據(jù)dba_objects確定創(chuàng)建時(shí)間是否匹配
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;

關(guān)于“Oracle動(dòng)態(tài)視圖v$active_session_history怎么應(yīng)用”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI