加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_泰州站长网 (http://www.0523zz.com/)- 视觉智能、AI应用、CDN、行业物联网、智能数字人!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2019-08-27 17:49:58 所属栏目:MySql教程 来源:波波说运维
导读:分享两个SQL,这两个SQL只是基础原型,大家自己自定义条件去做一些调整。主要是在前面讲过的dba_hist_active_sess_history相关sql上总结出来的比较实用的sql。 DBA_HIST_ACTIVE_SESS_HISTORY DBA_HIST_ACTIVE_SESS_HISTORY displays the history of the co

分享两个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

(编辑:云计算网_泰州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读