使用单条sql来查询出awr中的syatem statistics

参考自:
How to monitor system statistics from AWR snapshot by single SQL? (Doc ID 1320445.1)


适用于:
Oracle Server - Enterprise Edition - Version: 10.2.0.1 and later [Release: 10.2 and later ]
Information in this document applies to any platform.

目标:
SQL to monitor the latest changes of system statistics gathered by Automatic Workload Repository.

The following statistics are included. 

'redo size'
'physical reads'
'physical writes'
'session logical reads'
'user calls',
'parse count (hard)'
'gcs messages sent'
'ges messages sent'
'gc cr blocks received'
'gc current blocks received'


解决方案:

This SQL outputs the average value (per hours) between the latest two AWR snapshots.


col STAT_NAME for a30
with snap_shot as
(
select  begin_time,SNAP_ID,rank from (
select trunc(BEGIN_INTERVAL_TIME,'MI') begin_time,SNAP_ID,rank() over (order by snap_id desc) as rank from DBA_HIST_SNAPSHOT
) where rank<3
),
new as
(select * from snap_shot where rank = 1),
old as
(select * from snap_shot where rank = 2)
select stat1.STAT_NAME,stat2.value-stat1.value value,(new.begin_time-old.begin_time)*24 duration_in_hour,
    (stat2.value-stat1.value)/((new.begin_time-old.begin_time)*24) value_per_hour
 from DBA_HIST_SYSSTAT stat1, DBA_HIST_SYSSTAT stat2,new,old
where stat1.snap_id=old.snap_id
  and stat2.snap_id=new.snap_id
  and stat1.STAT_NAME=stat2.STAT_NAME
  and stat1.STAT_NAME in ('redo size','physical reads','physical writes','session logical reads','user calls',
  'parse count (hard)','gcs messages sent','ges messages sent','gc cr blocks received','gc current blocks received')
  order by stat1.STAT_NAME;



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sample Output:

SQL> col STAT_NAME for a30
SQL> with snap_shot as
  2  (
  3  select begin_time,SNAP_ID,rank from (
  4  select trunc(BEGIN_INTERVAL_TIME,'MI') begin_time,SNAP_ID,rank() over (order by snap_id desc) as rank from DBA_HIST_SNAPSHOT
  5  ) where rank<3
  6  ),
  7  new as
  8  (select * from snap_shot where rank = 1),
  9  old as
 10  (select * from snap_shot where rank = 2)
 11  select stat1.STAT_NAME,stat2.value-stat1.value value,(new.begin_time-old.begin_time)*24 duration_in_hour,
 12  (stat2.value-stat1.value)/((new.begin_time-old.begin_time)*24) value_per_hour
 13  from DBA_HIST_SYSSTAT stat1, DBA_HIST_SYSSTAT stat2,new,old
 14  where stat1.snap_id=old.snap_id
 15  and stat2.snap_id=new.snap_id
 16  and stat1.STAT_NAME=stat2.STAT_NAME
 17  and stat1.STAT_NAME in ('redo size','physical reads','physical writes','session logical reads','user calls',
 18  'parse count (hard)','gcs messages sent','ges messages sent','gc cr blocks received','gc current blocks received')
 19  order by stat1.STAT_NAME;

STAT_NAME                           VALUE DURATION_IN_HOUR VALUE_PER_HOUR
------------------------------ ---------- ---------------- --------------
gc cr blocks received                   0                1              0
gc current blocks received              0                1              0
gcs messages sent                       0                1              0
ges messages sent                       0                1              0
parse count (hard)                      0                1              0
physical reads                          7                1              7
physical writes                       377                1            377
redo size                          730992                1         730992
session logical reads               16159                1          16159
user calls                             38                1             38

10 rows selected.

SQL>

更多相关文章

  1. 数据库不支持中文解决方案(mysql)
  2. Mysql替代解决方案Cassandra
  3. [置顶] Android屏幕适配解决方案
  4. 物流货运移动APP解决方案
  5. 转:Android Studio Error:Connection timed out: connect.解决方
  6. android.os.NetworkOnMainThreadException的解决方案
  7. Android极光推送jPush混淆解决方案终极篇
  8. 【Android开发学习39】VideoView在GLSurfaceView之上显示的解决
  9. Android 3.2 以上转屏,切换屏幕,横竖屏(onConfigurationChanged)会

随机推荐

  1. 为什么推荐使用for-each而不是for循环遍
  2. Android源码50例汇总,欢迎各位下载
  3. 万字长文带你彻底理解synchronized关键字
  4. 面试官问我,使用Dubbo有没有遇到一些坑?我
  5. 你了解java中的几种编码方式?解决乱码问题
  6. Android的MediaPlayer
  7. 让各位久等了,你要的大杀器快要来了
  8. java日志框架体系梳理,简单直白
  9. Spring IOC知识点一网打尽!
  10. 为什么推荐使用try-with-resources代替tr