使用ASH监控历史会话,找出坏SQL
2009-11-30 17:08
309 查看
使用如下脚本可以监控历史会话经历过哪些等待事件,并且按照等待次数降序排列
select session_id,event,count(*),sum(time_waited) from v$active_session_history where session_state='WAITING'
and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
group by session_id,event order by 3 desc;
例子:
SQL> select session_id,event,count(*),sum(time_waited) from v$active_session_history where session_state='WAITING'
2 and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
3 group by session_id,event order by 3 desc;
输入 howlongago 的值: 5
原值 2: and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
新值 2: and time_waited>0 and sample_time>=(sysdate-5/(24*60))
SESSION_ID EVENT COUNT(*) SUM(TIME_WAITED)
---------- ------------------------------ ---------- ----------------
150 direct path write temp 3 20825
165 control file sequential read 2 21520
150 direct path read temp 2 38545
然后通过如下语句查询出引起该等待事件的sql_id
select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid;
SQL> select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid;
输入 howlongago 的值: 8
输入 sid 的值: 150
原值 1: select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid
新值 1: select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-8/(24*60)) and session_id=150
EVENT SESSION_ID SQL_ID P1 P2
------------------------------ ---------- ------------- ---------- ----------
P3
----------
direct path read temp 150 fqu3bkz2q6j26 201 58665
1
150 fqu3bkz2q6j26 1111838976 1
0
direct path read temp 150 fqu3bkz2q6j26 201 45897
1
EVENT SESSION_ID SQL_ID P1 P2
------------------------------ ---------- ------------- ---------- ----------
P3
----------
direct path read temp 150 fqu3bkz2q6j26 201 47753
1
再通过如下语句找到引起该等待事件的SQL
select sql_text from v$sqlarea where sql_id='&sql_id';
SQL> select sql_text from v$sqlarea where sql_id='&sql_id';
输入 sql_id 的值: fqu3bkz2q6j26
原值 1: select sql_text from v$sqlarea where sql_id='&sql_id'
新值 1: select sql_text from v$sqlarea where sql_id='fqu3bkz2q6j26'
SQL_TEXT
--------------------------------------------------------------------------------
select a.* from dict a,dict b order by 1
select session_id,event,count(*),sum(time_waited) from v$active_session_history where session_state='WAITING'
and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
group by session_id,event order by 3 desc;
例子:
SQL> select session_id,event,count(*),sum(time_waited) from v$active_session_history where session_state='WAITING'
2 and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
3 group by session_id,event order by 3 desc;
输入 howlongago 的值: 5
原值 2: and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
新值 2: and time_waited>0 and sample_time>=(sysdate-5/(24*60))
SESSION_ID EVENT COUNT(*) SUM(TIME_WAITED)
---------- ------------------------------ ---------- ----------------
150 direct path write temp 3 20825
165 control file sequential read 2 21520
150 direct path read temp 2 38545
然后通过如下语句查询出引起该等待事件的sql_id
select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid;
SQL> select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid;
输入 howlongago 的值: 8
输入 sid 的值: 150
原值 1: select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid
新值 1: select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-8/(24*60)) and session_id=150
EVENT SESSION_ID SQL_ID P1 P2
------------------------------ ---------- ------------- ---------- ----------
P3
----------
direct path read temp 150 fqu3bkz2q6j26 201 58665
1
150 fqu3bkz2q6j26 1111838976 1
0
direct path read temp 150 fqu3bkz2q6j26 201 45897
1
EVENT SESSION_ID SQL_ID P1 P2
------------------------------ ---------- ------------- ---------- ----------
P3
----------
direct path read temp 150 fqu3bkz2q6j26 201 47753
1
再通过如下语句找到引起该等待事件的SQL
select sql_text from v$sqlarea where sql_id='&sql_id';
SQL> select sql_text from v$sqlarea where sql_id='&sql_id';
输入 sql_id 的值: fqu3bkz2q6j26
原值 1: select sql_text from v$sqlarea where sql_id='&sql_id'
新值 1: select sql_text from v$sqlarea where sql_id='fqu3bkz2q6j26'
SQL_TEXT
--------------------------------------------------------------------------------
select a.* from dict a,dict b order by 1
相关文章推荐
- 使用ASH监控历史会话,找出坏SQL
- 使用ASH监控历史会话,找出坏SQL
- 使用Oracle自带的系统包和过程监控其它会话SQL语句的执行计划等信息
- 如何监控并找出系统中存在的大量的未使用绑定变量的SQL
- Druid数据源监控及慢sql记录使用文档
- 使用 utmpdump 监控 CentOS 用户登录历史
- Scripts:找出使用最多buffer get的SQL脚本perf_top_sql_by_buffer_gets.sql
- 如何利用ash监控会话
- 监控和剖析数据库操作 -- P6Spy、SQL Profiler、IronTrack SQL 使用简介
- SpringBoot中使用AOP 监控sql耗时
- 使用 utmpdump 监控 CentOS 用户登录历史
- 监控和剖析数据库操作 -- P6Spy、SQL Profiler、IronTrack SQL 使用简介
- 使用SQL 找出存在差异的数据
- 使用系统存储过程来监控SQLServer进程和会话详解
- SpringBoot之使用Druid连接池以及SQL监控和spring监控
- 使用aspnet_regsql.exe 创建ASPState数据库,用来保存session会话
- 巧妙使用SQL Profiler监控服务器
- Scripts:找出使用最高的10个表的脚本perf_top_10_tables.sql
- 使用aspnet_regsql.exe 创建ASPState数据库,用来保存session会话
- linux下使用rlwrap调用sqlplus中历史命令