2023-03-07 利用 ASH 視圖監(jiān)控數(shù)據(jù)庫性能

利用 ASH 視圖監(jiān)控數(shù)據(jù)庫性能

當前會話監(jiān)控語句:

select inst_id,sid,username,machine,program,module,action,sql_id,event,blocking_session,logon_time,prev_exec_start,client_info

from gv$session where status ='ACTIVE' and type <> 'BACKGROUND' order by inst_id,sid;

歷史活動會話檢查:監(jiān)控檢查最近10分鐘的數(shù)據(jù)庫等待事件的情況

select event,count(1)

from gv$active_session_history a

where a.sample_time > sysdate - 1/144

group by event

order by count(1) desc;

select event,sql_id,count(1)

from gv$active_session_history a

where a.sample_time > sysdate - 1/144

group by event,sql_id

order by count(1) desc;

最近一段時間每一分鐘的ASH中出現(xiàn)的行數(shù),記錄數(shù)越多咏瑟,說明數(shù)據(jù)庫越活躍,負載越大归榕,可能等待越多

select trunc(sample_time,'mi'),count(1)

from gv$active_session_history

group by trunc(sample_time,'mi')

order by 1;

select trunc(sample_time,'mi'),event,count(1)

from gv$active_session_history

where

sample_time >=to_date('20181016 17:51:00','yyyymmdd hh24:mi:ss')

and

sample_time <=to_date('20181016 17:54:00','yyyymmdd hh24:mi:ss')

group by

trunc(sample_time,'mi'),event

order by 1;

利用 ASH 視圖分析數(shù)據(jù)庫阻塞問題

1 .? 分析找出會話阻塞出現(xiàn)的時間段

select trunc(sample_time,'mi'),count(1) from dba_hist_active_sess_histroy

where sample_time > to_date('20180626 01:25:00','yyyymmdd hh24:mi:ss')

and? sample_time < to_date('20180626 01:40:00','yyyymmdd hh24:mi:ss')

and event is not null

group by trunc(sample_time,'mi')

having count(1)>2

order by 1;

2 .? 分析會話阻塞的等待事件,進一步縮小時間范圍

關(guān)注新出現(xiàn)的等待事件和等待事件次數(shù)變多的

select trunc(sample_time,'mi'),event,count(1) from dba_hist_active_sess_histroy

where sample_time > to_date('20180626 01:26:00','yyyymmdd hh24:mi:ss')

and? sample_time < to_date('20180626 01:31:00','yyyymmdd hh24:mi:ss')

and event is not null

group by trunc(sample_time,'mi'),event

having count(1)>2

order by 1,3;

3 .? 定位會話阻塞的源頭

關(guān)注這一列:final_block

with ash as (select instance_number,session_id,event,blocking_session,program,

to_char(sample_time,'YYYYMMDD HH24MISS') sample_time,sample_id,blocking_inst_id

from dba_hist_active_sess_histroy where

sample_time > to_date('20180626 01:26:00','yyyymmdd hh24:mi:ss')

and sample_time < to_date('20180626 01:31:00','yyyymmdd hh24:mi:ss'))

select * from (

select sample_time,blocking_session final_block,SYS_CONNECT_BY_PATH(session_id,',') sid_chain,

SYS_CONNECT_BY_PATH(event,',') event_chain

from ash start with session_id is not null

CONNECT by prior blocking_session = session_id and

prior instance_number = blocking_inst_id and sample_id = prior sample_id) a

where instr(sid_chain,final_block)=0 and not EXISTS

(select 1 from ash b where a.final_block=b.session_id and b.blocking_session is not null)

order by sample_time

實戰(zhàn)案例:

select substr(sample_time,1,16),count(1) from dba_hist_active_sess_histroy

where sample_time >'2018-10-09 09.00.00'

and sample_time < '2018-10-09 10.00.00'

and event is not null

group by SUBSTR(sample_time,1,16)

order by 1;

select substr(sample_time,1,16),event,count(1) from dba_hist_active_sess_histroy

where sample_time >'2018-10-09 09.10.00'

and sample_time < '2018-10-09 10.20.00'

and event is not null

group by SUBSTR(sample_time,1,16),event

having count(1)>2

order by 1;

關(guān)注這一列:final_block

with ash as (select instance_number,session_id,event,blocking_session,program,

to_char(sample_time,'YYYYMMDD HH24MISS') sample_time,sample_id,blocking_inst_id

from dba_hist_active_sess_histroy where

sample_time > to_date('20180626 01:26:00','yyyymmdd hh24:mi:ss')

and sample_time < to_date('20180626 01:31:00','yyyymmdd hh24:mi:ss'))

select * from (

select sample_time,blocking_session final_block,SYS_CONNECT_BY_PATH(session_id,',') sid_chain,

SYS_CONNECT_BY_PATH(event,',') event_chain

from ash start with session_id is not null

CONNECT by prior blocking_session = session_id and

prior instance_number = blocking_inst_id and sample_id = prior sample_id) a

where instr(sid_chain,final_block)=0 and not EXISTS

(select 1 from ash b where a.final_block=b.session_id and b.blocking_session is not null)

order by sample_time

進一步確定這個會話在做什么:

select inst_id,sample_time,session_id,sql_id,program,module,action,client_id,event

from? gv$active_session_history

where session_id=574 and session_serial# = 141

order by sample_time;

select inst_id,sample_time,session_id,sql_id,sql_opname,program,module,action,client_id,event

from gv$active_session_history

where sample_time > '2018-10-09 09.11.00'

and sample_time < '2018-10-09 09.20.00'

and event ='library cache pin'

and inst_id=1

order by sample_time;

CURRENT_obj#? -----這個字段

select sample_time,sql_id,sql_opname,event,CURRENT_obj# from v$active_session_history

where event='db file sequential read'

order by sample_time desc;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末吱涉,一起剝皮案震驚了整個濱河市刹泄,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌怎爵,老刑警劉巖特石,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異疙咸,居然都是意外死亡,警方通過查閱死者的電腦和手機风科,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門撒轮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人贼穆,你說我怎么就攤上這事题山。” “怎么了故痊?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵顶瞳,是天一觀的道長。 經(jīng)常有香客問我愕秫,道長慨菱,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任戴甩,我火速辦了婚禮符喝,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘甜孤。我一直安慰自己协饲,他們只是感情好,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布缴川。 她就那樣靜靜地躺著茉稠,像睡著了一般。 火紅的嫁衣襯著肌膚如雪把夸。 梳的紋絲不亂的頭發(fā)上而线,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機與錄音,去河邊找鬼吞获。 笑死况凉,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的各拷。 我是一名探鬼主播刁绒,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼烤黍!你這毒婦竟也來了知市?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤速蕊,失蹤者是張志新(化名)和其女友劉穎嫂丙,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體规哲,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡跟啤,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了唉锌。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片隅肥。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖袄简,靈堂內(nèi)的尸體忽然破棺而出腥放,到底是詐尸還是另有隱情,我是刑警寧澤绿语,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布秃症,位于F島的核電站,受9級特大地震影響吕粹,放射性物質(zhì)發(fā)生泄漏种柑。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一匹耕、第九天 我趴在偏房一處隱蔽的房頂上張望莹规。 院中可真熱鬧,春花似錦泌神、人聲如沸良漱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽母市。三九已至,卻和暖如春损趋,著一層夾襖步出監(jiān)牢的瞬間患久,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留蒋失,地道東北人返帕。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像篙挽,于是被迫代替她去往敵國和親荆萤。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容