分享兩個(gè)實(shí)用SQL--查看故障時(shí)間等待事件、問(wèn)題sql及會(huì)話訪問(wèn)次數(shù)
分享兩個(gè)SQL,這兩個(gè)SQL只是基礎(chǔ)原型,大家自己自定義條件去做一些調(diào)整。主要是在前面講過(guò)的dba_hist_active_sess_history相關(guān)sql上總結(jié)出來(lái)的比較實(shí)用的sql。
DBA_HIST_ACTIVE_SESS_HISTORY
DBA_HIST_ACTIVE_SESS_HISTORY displays the history of the contents of the in-memory active session history of recent system activity. This view contains snapshots of V$ACTIVE_SESSION_HISTORY. See "V$ACTIVE_SESSION_HISTORY" for further interpretation details for many of these columns (except SNAP_ID, DBID, and INSTANCE_NUMBER).
查看故障時(shí)間段等待事件、問(wèn)題sql id及會(huì)話訪問(wèn)次數(shù)
- --alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
- select trunc(sample_time, 'mi') tm, sql_id, nvl(event,'CPU'),count(distinct session_id) cnt
- from dba_hist_active_sess_history
- where sample_time between to_date('2019-08-22 14:00:00') and
- to_date('2019-08-22 14:30:00')
- group by trunc(sample_time, 'mi'), sql_id,nvl(event,'CPU')
- order by cnt desc;
查看該sql相關(guān)的等待事件及對(duì)應(yīng)的會(huì)話訪問(wèn)次數(shù)
- select sql_id, nvl(event, 'CPU'), count(distinct session_id) sz
- from dba_hist_active_sess_history a, dba_hist_snapshot b
- where sample_time between to_date('2019-08-22 14:00:00') and
- to_date('2019-08-22 15:00:00')
- and sql_id = '4ksvn2rgjnhcm'
- and a.snap_id = b.snap_id
- and a.instance_number = b.instance_number
- group by sql_id, nvl(event, 'CPU')
- order by sz desc;