2023-03-07 利用 ASH 视图监控数据库性能

利用 ASH 视图监控数据库性能

当前会话监控语句:

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;

历史活动会话检查:监控检查最近10分钟的数据库等待事件的情况

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中出现的行数,记录数越多,说明数据库越活跃,负载越大,可能等待越多

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 视图分析数据库阻塞问题

1 .  分析找出会话阻塞出现的时间段

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 .  分析会话阻塞的等待事件,进一步缩小时间范围

关注新出现的等待事件和等待事件次数变多的

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 .  定位会话阻塞的源头

关注这一列: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 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;

关注这一列: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;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,884评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,347评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,435评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,509评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,611评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,837评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,987评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,730评论 0 267
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,194评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,525评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,664评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,334评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,944评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,764评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,997评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,389评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,554评论 2 349

推荐阅读更多精彩内容