select METRIC_NAME,VALUE from SYS.V_$SYSMETRIC where METRIC_NAME IN ('Database CPU Time Ratio','Database Wait Time Ratio') AND INTSIZE_CSEC = (select max(INTSIZE_CSEC) from SYS.V_$SYSMETRIC); METRIC_NAME VALUE Database Wait Time Ratio 31.3499111 Database CPU Time Ratio 68.6500888
Oracle10g数据库中的V$SYSMETRIC视图中存在一些非常有用的响应时间数据,其中两个比较重要的就是Wait Time Ratio 和Database CPU Time Ratio.上面的查询显示了数据库中最新的关于这两个统计数据的快照,这将有助于帮助我们确定是否数据库正在经历着一个比较高的等待百分率和瓶颈。数据库的CPU Time Ratio是由数据库中的"database time"的数值除以CPU的数量,"database time"定义为数据库消耗在用户级别调用所花费的时间(不包括实例的后台进程活动所消耗的时间)。比较高的值(90%-95%以上)代表很少等待和瓶颈活动,因为各个系统不同,这个阀值只能作为一个一般的规则来使用。 还可以使用如下的查询来迅速查看最新一个小时的信息,看看数据库的总性能如何:
select end_time,value from sys.v_$sysmetric_history where metric_name = 'Database CPU Time Ratio' order by 1; END_TIME VALUE 2007-1-24 2 3.21949216 2007-1-24 2 3.01443414 2007-1-24 2 9.75636353 2007-1-24 2 9.28581409 2007-1-24 2 43.3490481 2007-1-24 2 38.8366361 2007-1-24 2 32.0272511 2007-1-24 2 0 2007-1-24 2 22.9580733 2007-1-24 2 33.0615102 2007-1-24 2 43.1294933
可以从V$SYSMETRIC_SUMMARY视图中获得数据库整体性能效率的最大、最小和平均值:
select CASE METRIC_NAME WHEN 'SQL Service Response Time' then 'SQL Service Response Time (secs)' WHEN 'Response Time Per Txn' then 'Response Time Per Txn (secs)' ELSE METRIC_NAME END METRIC_NAME, CASE METRIC_NAME WHEN 'SQL Service Response Time' then ROUND((MINVAL / 100),2) WHEN 'Response Time Per Txn' then ROUND((MINVAL / 100),2) ELSE MINVAL END MININUM, CASE METRIC_NAME WHEN 'SQL Service Response Time' then ROUND((MAXVAL / 100),2) WHEN 'Response Time Per Txn' then ROUND((MAXVAL / 100),2) ELSE MAXVAL END MAXIMUM, CASE METRIC_NAME WHEN 'SQL Service Response Time' then ROUND((AVERAGE / 100),2) WHEN 'Response Time Per Txn' then ROUND((AVERAGE / 100),2) ELSE AVERAGE END AVERAGE from SYS.V_$SYSMETRIC_SUMMARY where METRIC_NAME in ('CPU Usage Per Sec', 'CPU Usage Per Txn', 'Database CPU Time Ratio', 'Database Wait Time Ratio', 'Executions Per Sec', 'Executions Per Txn', 'Response Time Per Txn', 'SQL Service Response Time', 'User Transaction Per Sec') ORDER BY 1; METRIC_NAME MININUM MAXIMUM AVERAGE CPU Usage Per Sec 0 53.9947577 11.1603280 CPU Usage Per Txn 0 168.731666 24.8848615 Database CPU Time Ratio 0 87.1866295 35.8114730 Database Wait Time Ratio 0 90.7141859 64.1885269 Executions Per Sec 0 540.768348 114.852472 Executions Per Txn 0 1911 279.912779 Response Time Per Txn (secs) 0 3.88 0.66 SQL Service Response Time (secs) 0 0 0 User Transaction Per Sec 0 4.70183486 0.94469007
上面的查询包含了更多的具体的响应时间数据。DBA们还需要收集在系统级别上的用户通讯的平均响应时间,上面的查询给出了需要的结果。假如用户抱怨响应时间太慢,那么DBA就应该查看Response Time Per Txn和SQL Service Response Time数据是否存在数据库问题。 假如响应时间不在是那么渴求,那么DBA就会想了解究竟是什么类型的用户活动让数据库的响应变得如此的慢,在Oracle10g数据库之前,这些信息 是比较难获取的,但是现在就变得非常轻易,执行如下查询:
select case db_stat_name when 'parse time elapsed' then 'soft parse time' else db_stat_name end db_stat_name, case db_stat_name when 'sql execute elapsed time' then time_secs - plsql_time when 'parse time elapsed' then time_secs - hard_parse_time else time_secs end time_secs, case db_stat_name when 'sql execute elapsed time' then round(100 * (time_secs - plsql_time) / db_time,2) when 'parse time elapsed' then round(100 * (time_secs - hard_parse_time) / db_time,2) else round(100 * time_secs / db_time,2) end pct_time from (select stat_name db_stat_name, round((value / 1000000),3) time_secs from sys.v_$sys_time_model where stat_name not in('DB time','background elapsed time', 'background cpu time','DB CPU')), (select round((value / 1000000),3) db_time from sys.v_$sys_time_model where stat_name = 'DB time'), (select round((value / 1000000),3) plsql_time from sys.v_$sys_time_model where stat_name = 'PL/SQL execution elapsed time'), (select round((value / 1000000),3) hard_parse_time from sys.v_$sys_time_model where stat_name = 'hard parse elapsed time') order by 2 desc; DB_STAT_NAME TIME_SECS PCT_TIME sql execute elapsed time 65.644 89.7 hard parse elapsed time 26.661 36.43 PL/SQL execution elapsed time 12.766 17.44 PL/SQL compilation elapsed time 6.353 8.68 soft parse time 2.15 2.94 connection management call elapsed time 1.084 1.48 hard parse (sharing criteria) elapsed time 0.448 0.61 repeated bind elapsed time 0.026 0.04 failed parse elapsed time 0.009 0.01 hard parse (bind mismatch) elapsed time 0.002 0 RMAN cpu time (backup/restore) 0 0 inbound PL/SQL rpc elapsed time 0 0 sequence load elapsed time 0 0 java execution elapsed time 0 0 failed parse (out of shared memory) elapsed time 0 0