ORACLE DBTime詳解

yepkeepmoving發表於2016-11-04

    DB TIME是所有前臺session花費在database呼叫上的總和時間,microsecond(微妙),AWR展示DBTIME單位為分鐘(MINS,是檢視資料庫系統總體負載的主要參考引數,數值主要來自檢視DBA_HIST_SYS_TIME_MODEL(歷史db time資料來源)v$sys_time_modelDBA_HIST_SYSSTAT(不準確)、V$SYSSTAT
一、DBTime計算公式:
    
DB TIME= DB CPU + Non-Idle Wait + Wait on CPU queue
                (Non-Idle Wait= enq:TX + cursor pin S on X + latch : xxx + db file sequential read + ………)

二、最近7天的DBTime檢視指令碼
    (主要從DBA_HIST_SYS_TIME_MODEL 和dba_hist_snapshot取歷史資料,預設每條記錄為1小時快照資料)

set linesize 200 ;
set pagesize 20000 ;
col DATE_TIME  for a45 ;
col STAT_NAME  for a10 ;
WITH sysstat AS (
  SELECT
    sn.begin_interval_time begin_interval_time,
    sn.end_interval_time end_interval_time,
    ss.stat_name stat_name,
    ss.
  VALUE
    e_value,
    lag (ss. VALUE, 1) over (ORDER BY ss.snap_id) b_value
  FROM
    DBA_HIST_SYS_TIME_MODEL ss,
    dba_hist_snapshot sn
  WHERE
    trunc (sn.begin_interval_time) >= sysdate - 7
  AND ss.snap_id = sn.snap_id
  AND ss.dbid = sn.dbid
  AND ss.instance_number = sn.instance_number
  AND ss.dbid = (SELECT dbid FROM v$database)
  AND ss.instance_number = (
    SELECT
      instance_number
    FROM
      v$instance
  )
  AND ss.stat_name = 'DB time'
) SELECT
  to_char (
    BEGIN_INTERVAL_TIME,
    'yyyy-mm-dd hh24:mi'
  ) || to_char (
    END_INTERVAL_TIME,
    ' hh24:mi'
  ) date_time,
  stat_name,
  round(
    (e_value - nvl(b_value, 0))/60/1000/1000 ,
    2
  ) dbtime_value
FROM
  sysstat
WHERE
  (e_value - nvl(b_value, 0)) > 0
AND nvl (b_value, 0) > 0  ;
三、實時檢視DBTime指令碼

當前dbtime數值查詢:
select value/1000000/60 now_dbtime from v$SYS_TIME_MODEL where STAT_NAME = 'DB time';

最近的歷史dbtime基準數值查詢:
select t.snap_id,to_char(t.begin_interval_time,'yyyy-mm-dd hh24:mi:ss') btime,to_char(t.end_interval_time,'yyyy-mm-dd hh24:mi:ss') etime ,e.value/1000000/60 latest_dbtime from DBA_HIST_SYS_TIME_MODEL e,dba_hist_snapshot t
WHERE
e.STAT_NAME = 'DB time'
and t.snap_id=e.snap_id
and e.snap_id=(select max(snap_id) from dba_hist_snapshot) ;

實時檢視dbtime負載指令碼:
col STAT_NAME for a35;
col END_INTERVAL_TIME   for a35;
col BEGIN_INTERVAL_TIME  for a35;
col NOW_DBTIME for 9999999.9999;
col LATEST_DBTIME for 9999999.9999;
col DB_WORKLOAD for a15;
set line 200;
set pagesize 20000;

with tmp as (select t.snap_id,t.begin_interval_time btime,t.end_interval_time etime ,e.value/1000000/60 latest_dbtime from DBA_HIST_SYS_TIME_MODEL e,dba_hist_snapshot t
WHERE
e.STAT_NAME = 'DB time'
and t.snap_id=e.snap_id
and e.snap_id=(select max(snap_id) from dba_hist_snapshot))
select tmp.latest_dbtime,value/1000000/60 now_dbtime,(((systimestamp+0)-(etime+0 ))*24*60) Elapsed  ,round(value/1000000/60-tmp.latest_dbtime,2) real_dbtime ,round((value/1000000/60-tmp.latest_dbtime)/(((systimestamp+0)-(etime+0 ))*24*60)*100,2)||'%' db_workload
from v$SYS_TIME_MODEL sm ,tmp  where STAT_NAME = 'DB time';

、DBTime附錄
  1)相關重要檢視、表
    DBA_HIST_SYS_TIME_MODEL
    dba_hist_snapshot

    DBA_HIST_SYSSTAT
    v$sys_time_model

    V$SYSSTAT
  2)平均負載計算(上面的db_workload 為負載百分比)

        Average Active Session AAS= DB time/Elapsed Time 
                如果僅有2個邏輯CPU,而3個session在60分鐘都100%僅消耗CPU,那麼總有一個要wait on queue
                DB CPU = 2* 60 mins ,wait on CPU queue= 60 mins
                AAS= (120+ 60)/60=3
        主機load 也為3,此時vmstat 看waiting for run time




DBA_HIST_SYS_TIME_MODEL

DBA_HIST_SYS_TIME_MODEL displays historical system time model statistics. This view contains snapshots of V$SYS_TIME_MODEL.

Column Datatype NULL Description
SNAP_ID NUMBER   Unique snapshot ID
DBID NUMBER   Database ID for the snapshot
INSTANCE_NUMBER NUMBER   Instance number for the snapshot
STAT_ID NUMBER   Statistic ID
STAT_NAME VARCHAR2(64)   Statistic name
VALUE NUMBER   Statistic value

DBA_HIST_SYSSTAT

DBA_HIST_SYSSTAT displays historical system statistics information. This view contains snapshots of V$SYSSTAT.

Column Datatype NULL Description
SNAP_ID NUMBER   Unique snapshot ID
DBID NUMBER   Database ID for the snapshot
INSTANCE_NUMBER NUMBER   Instance number for the snapshot
STAT_ID NUMBER   Statistic identifier
STAT_NAME VARCHAR2(64)   Statistic name
VALUE NUMBER   Statistic value

DBA_HIST_SNAPSHOT

DBA_HIST_SNAPSHOT displays information about the snapshots in the Workload Repository.

Column Datatype NULL Description
SNAP_ID NUMBER NOT NULL Unique snapshot ID
DBID NUMBER NOT NULL Database ID for the snapshot
INSTANCE_NUMBER NUMBER NOT NULL Instance number for the snapshot
STARTUP_TIME TIMESTAMP(3) NOT NULL Startup time of the instance
BEGIN_INTERVAL_TIME TIMESTAMP(3) NOT NULL Time at the beginning of the snapshot interval
END_INTERVAL_TIME TIMESTAMP(3) NOT NULL Time at the end of the snapshot interval; the actual time the snapshot was taken
FLUSH_ELAPSED INTERVAL DAY(5) TO SECOND(1)   Amount of time to perform the snapshot
SNAP_LEVEL NUMBER   Snapshot level
ERROR_COUNT NUMBER   Number of errors occurring in the tables for the particular snapshot
SNAP_FLAG NUMBER   Condition under which the snapshot was inserted. Possible values are:

0 - Snapshot was taken automatically by the Manageability Monitor Process (MMON process)

1 - Manual snapshot created using a PL/SQL package

2 - Imported snapshot

4 - Snapshot taken while Diagnostic Pack or Tuning Pack was not enabled

SNAP_TIMEZONE INTERVAL DAY(0) TO SECOND(0)   Snapshot time zone expressed as offset from UTC (Coordinated Universal Time) time zone


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