Oracle 快速性能诊断工具ASH

Oracle 10g 的性能调优时,可以使用到的工具主要有三个,分别为ASH(active session history)AWR(automatic workload repository)ADDM(automatic database diagnostic monitor) 。这些工具比9i 中的statspack 有很大提升。

试想,在数据库出现性能问题,慢得要死的时候,最需要知道的就是系统慢在哪里。知道得越快越好。如果等待某个取样时间到了之后才能分析,这不是一个令人满意的解决过程。 以前 遇到这种情况,我们会去手工查动态性能视图,但在10g 中,使用ASH就可以快速定位问题。

 

ASH 工具主要查询的是v$active_session_history 视图,根据这个视图我们可以延伸出很多功能。

(miki西游 @mikixiyou 原文http://mikixiyou.iteye.com/blog/1630056 )

-----------------------------------------
--
-- 最近5分钟消耗CPU Top 10
--
-----------------------------------------
SQL> select * from
(
select session_id, session_serial#, count(*)
from v$active_session_history
where session_state= 'ON CPU' and
 sample_time > sysdate - interval '5' minute
group by session_id, session_serial#
order by count(*) desc
)
where rownum <= 10;
--------------------------------------------
--
-- 最近5分活动会话Top 10
--
--------------------------------------------
SQL> select * from
(
select session_id, session_serial#,count(*)
from v$active_session_history
where session_state='WAITING'  and
 sample_time >  sysdate - interval '5' minute
group by session_id, session_serial#
order by count(*) desc
)
where rownum <= 10;

这两个查询可以查询出数据库实例中最近5分钟的活动会话,但这些是什么应用的连接和他们执行什么SQL,需要进一步分析。

--------------------
--
-- Who is that SID?
--
--------------------

set lines 200
col username for a10
col osuser for a10
col machine for a10
col program for a10
col resource_consumer_group for a10
col client_info for a10

SQL> select  serial#,
 username,
 osuser,
 machine,
 program,
 resource_consumer_group,
 client_info
from v$session where sid=&sid;

-------------------------
--
-- What did that SID do?
--
-------------------------

SQL> select distinct sql_id, session_serial# from v$active_session_history
where sample_time >  sysdate - interval '5' minute
and session_id=&sid;
----------------------------------------------
--
-- Retrieve the SQL from the Library Cache:
--
----------------------------------------------
col sql_text for a80
SQL> select sql_text from v$sql where sql_id='&sqlid';

通过ASH,可以快速定位数据库实例的活动情况。

猜你喜欢

转载自mikixiyou.iteye.com/blog/1630056