欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Oracle動態(tài)視圖v$active_session_history實戰(zhàn)示例

 更新時間:2023年03月08日 15:04:49   作者:Yideng  
這篇文章主要為大家介紹了Oracle動態(tài)視圖v$active_session_history實戰(zhàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

Oracle動態(tài)視圖實戰(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.
  • 有幾個關(guān)鍵點:1秒采集一次,執(zhí)行時間很快遠(yuǎn)小于1秒的SQL基本不會采集到,只寫入非空閑狀態(tài)的事件,循環(huán)存放活動越多保存的時間就越短。

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

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

a.應(yīng)用場景:開發(fā)反應(yīng)2023-03-02 00:22至00:35,數(shù)據(jù)落盤慢,根據(jù)情況查看此時間段的主要活動事件,數(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 hh24:mi:ss') and
       to_date('2023-03-02 00:35:00', 'yyyy-mm-dd hh24: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 hh24:mi:ss') and
       to_date('2023-03-02 00:35:00', 'yyyy-mm-dd hh24:mi:ss')
 group by sql_id, event, BLOCKING_INST_ID, blocking_session
 order by 1;
b.現(xiàn)在我們已經(jīng)得到兩個關(guān)鍵信息:sql_id與阻塞事件,首先根據(jù)sql_id我們可以再進一步使用此視圖,實際中可以多調(diào)整幾個較小的時間段,以突出最有代表的信息
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 hh24:mi:ss') and
       to_date('2023-03-02 00:25:00', 'yyyy-mm-dd hh24: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 hh24:mi:ss') and
       to_date('2023-03-02 00:35:00', 'yyyy-mm-dd hh24: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語句

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

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

關(guān)鍵點

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

  • 總結(jié)時間:

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

在對開發(fā)進行嚴(yán)刑拷打逼問后(如果開發(fā)小哥不松口怎么辦?下節(jié)預(yù)告:可以直接查詢時間段的DDL語句執(zhí)行情況),終于告訴我當(dāng)天晚上時間點上對這兩張表做了大量新建分區(qū)表的操作,至此基本水落石出。

#根據(jù)dba_objects確定創(chuàng)建時間是否匹配
select owner,
       object_name,
       object_type,
       to_char(created, 'yyyy-mm-dd hh24: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 hh24: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)鍵點b:我一定要記住,應(yīng)該最先查看OSWatch的數(shù)據(jù),排除OS的問題。至于OSW怎么部署,運行和查看以后章節(jié)再補充。同時也得查看database的alert.log日志,有驚喜╰(°▽°)╯

以上就是Oracle動態(tài)視圖v$active_session_history實戰(zhàn)示例的詳細(xì)內(nèi)容,更多關(guān)于Oracle動態(tài)視圖的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論