Oracle动态视图v$active_session_history实战示例(oracle视图创建语句在哪查看)燃爆了

随心笔谈9个月前发布 admin
85 0

a.应用场景:开发反应2023-03-02 00:22至00:35,数据落盘慢,根据情况查看此时间段的主要活动事件,数量,与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.现在我们已经得到两个关键信息:sql_id与阻塞事件,首先根据sql_id我们可以再进一步使用此视图,实际中可以多调整几个较小的时间段,以突出最有代表的信息
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;
结论:可以看出大量并发等待,最终是发现有什么阻塞了此SQL语句

© 版权声明

相关文章