分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

分享两个SQL,这两个SQL只是基础原型,大家自己自定义条件去做一些调整。主要是在前面讲过的dba_hist_active_sess_history相关sql上总结出来的比较实用的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).

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

查看故障时间段等待事件、问题sql id及会话访问次数

  1. --alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; 
  2. select trunc(sample_time, 'mi') tm, sql_id, nvl(event,'CPU'),count(distinct session_id) cnt 
  3.  from dba_hist_active_sess_history 
  4.  where sample_time between to_date('2019-08-22 14:00:00') and 
  5.  to_date('2019-08-22 14:30:00') 
  6.  group by trunc(sample_time, 'mi'), sql_id,nvl(event,'CPU') 
  7.  order by cnt desc; 

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

查看该sql相关的等待事件及对应的会话访问次数

  1. select sql_id, nvl(event, 'CPU'), count(distinct session_id) sz 
  2.  from dba_hist_active_sess_history a, dba_hist_snapshot b 
  3.  where sample_time between to_date('2019-08-22 14:00:00') and 
  4.  to_date('2019-08-22 15:00:00') 
  5.  and sql_id = '4ksvn2rgjnhcm' 
  6.  and a.snap_id = b.snap_id 
  7.  and a.instance_number = b.instance_number 
  8.  group by sql_id, nvl(event, 'CPU') 
  9.  order by sz desc; 

分享两个实用SQL--查看故障时间等待事件、问题sql及会话访问次数

【编辑推荐】

  1. 深入浅出MySQL索引的那些事儿
  2. MySQL数据库目录下面的db.opt是干什么用的?
  3. 同事用这2个小技巧,让SQL语句效率提升了1000倍
  4. MySQL导入导出命令-mysqldump
  5. 如何删除MySQL用户帐户

【责任编辑:赵宁宁 TEL:(010)68476606】

点赞 0

dawei

【声明】:天津站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。