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