從資料字典中獲取ash資訊

xypincle發表於2017-05-01

  1. 1.v$active_session_history 獲取當前或最近資料庫中的會話資訊
  2. 2.dba_hist_active_sess_history 儲存ash歷史資訊
  3. 3.檢視過去15分鐘內資料庫中所有事件以及它們總的等待時間:
  4. select s.event,sum(s.wait_time + s.time_waited) total_wait
  5. from v$active_session_history s
  6. where s.sample_time between sysdate-1/24/4 and sysdate-1/24/4
  7. group by s.event
  8. order by 2 desc;

  9. 4.如果想得到更具體的會話資訊,並且想檢視過去15分鐘內使用最多cpu資源的前5位會話,可以提交下面的語句:
  10. select * from
  11. (select s.username,s.module,s.sid,s.serial#,count(*)
  12. from v$active_session_history h,v$session s
  13. where h.session_id = s.sid
  14. and h.session_serial# = s.serial#
  15. and session_state = 'ON CPU' and sample_time > sysdate - interval '15' minute
  16. group by s.username,s.module,s.sid,s.serial#
  17. order by count(*) desc
  18. )
  19. where rownum <= 5;

  20. 5.如果想要檢視某個給定取樣週期內使用最多的資料庫物件,則可以將v$active_session_history和dba_objects連線起來獲得資訊:
  21. select * from
  22. (select o.object_name,o.object_type,s.event,sum(s.wait_time + s.time_waited) total_waited
  23. from v$active_session_history s,dba_objects o
  24. where s.sample_time > sysdate - interval '15' minute
  25. and s.current_obj# = o.object_id
  26. group by o.object_name,o.object_type,s.event
  27. order by 4 desc
  28. )
  29. where rownum <= 5;

  30. 6.查詢某天使用資源最多的使用者:
  31. select * from
  32. (select u.username,h.module,h.session_id sid,h.session_serial# serial#,count(*)
  33. from dba_hist_active_sess_history h,dba_users u
  34. where h.user_id = u.user_id
  35. and session_state = 'ON CPU'
  36. and (sample_time between to_date('20170101 00:00:00','yyyymmdd hh24:mi:ss') and to_date('20170131 23:59:59','yyyymmdd hh24:mi:ss'))
  37. and u.username != 'SYS'
  38. group by u.username,h.module,h.session_id,h.session_serial#
  39. order by count(*) desc
  40. )
  41. where rownum <= 5;

  42. 接下來要關注具體的資料庫物件,可以面向同樣的時間幀提交下面的查詢:
  43. select * from
  44. (select o.object_name,o.object_type,s.event,sum(s.wait_time + s.time_waited) total_waited
  45. from v$active_session_history s,dba_objects o
  46. where (sample_time between to_date('20170101 00:00:00','yyyymmdd hh24:mi:ss') and to_date('20170131 23:59:59','yyyymmdd hh24:mi:ss'))
  47. and s.current_obj# = o.object_id
  48. group by o.object_name,o.object_type,s.event
  49. order by 4 desc
  50. )
  51. where rownum <= 5;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28878983/viewspace-2138260/,如需轉載,請註明出處,否則將追究法律責任。

相關文章