已索引
该文章已被其它文章引用。
由于 v$transaction 视图并没有相应的历史视图,并不能很轻松地定位到过去使用undo最多的会话或者SQL语句。
但是我们可以通过下面的方法来进行分析。
1.通过如下查询找出undo使用较多的时间段(或者根据业务报ORA-30036的时候来确定时间范围):
set pages 100
select to_char(begin_time,'yyyy-mm-dd hh24:mi:ss') as begin_time,
to_char(end_time,'yyyy-mm-dd hh24:mi:ss') as end_time,
round(maxquerylen/60, 0) "MAX_QUEY(m)",
maxquerysqlid,
undotsn,
undoblks,
txncount,
unexpiredblks,
expiredblks,
round(tuned_undoretention/60,0) "Tuned(m)"
from dba_hist_undostat a
-- where end_time > sysdate - 2
-- where begin_time between to_date('2023-11-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2023-11-02 00:00:00','yyyy-mm-dd hh24:mi:ss')
order by undoblks;
2.查看该时间范围内的数据库活动
set lines 200
col machine for a20
col sample_time for a26
col event for a20
col sql_opname for a10
select SAMPLE_TIME,SQL_ID,SQL_OPNAME,MACHINE from dba_hist_active_sess_history;
从上面查询到的该时段的数据库活动,再结合 AWR 和 ASH 中的信息进行分析定位:
- 配合 AWR 中的 Segment Statistics 中的 Segemnts by DB Blocks Changes 来定位对象。
- 还可以从 ASH 中的 Top SQL Command Types 和 AWR、ASH 中的 Top SQL 来分析。
建议周期性(如每5分钟)对 undo 的使用情况进行监控,将使用 undo 最多 sql_id 和 undo 量打印出来,如此,当需要查询过去某时间谁消耗了最多的 undo 时,就可以通过 zabbix 迅速找到。