oracle performance tuning效能優化學習系列(五)

wisdomone1發表於2013-03-11

oracle效能優化學習系列(五)
awr概述
1,如配置statistics_level=typical or all,自動啟用awr
2,如配置為basic,使用dbms_workload_repository手工收集;但可能收集的統計資訊不全;
3,awr收集統計資訊包含:
    1,segment的相關統計
    2,基於各項活動使用情況的時間維度統計;顯示在v$sys_time_model and v$sess_time_model
    3,v$sysstat and v$sesstat;
    4,sql語句
    5,ash統計;活動會話的歷史統計資訊
4,snapshots快照
   1,在取樣間隔收集的一系列歷史資料;
   2,awr每1小時收集snapshot,並在awr中保持8天;
   3,手工也可以收集snapshot,但一般沒必要;
   4,addm會分析比對snapshot以判斷效能是否最佳

5,baselines基線
   1,用於和相同時間範圍比較的特定時間範圍的效能資料;
   2,基線包含於快照內;
   3,快照可從自動化的awr清理程式排除在外;--dbms_workload_repository.drop_baseline自快照刪除某個基線
   4,或者永久儲存      
  
   5,資料庫的幾種基線型別:
         1,fixed baselines 固定性的基線
         2,moving window baseline 遷移視窗基線
         3,baseline templates 基線模板
        
         1,fixed baselines 固定性的基線
            即固定的,連續性的過去一個時間範圍;指定基線前,一定要仔細分析;此時間範圍是否
            為系統最佳效能時間;
         2,moving window baseline 變動的視窗基線
            1,它對應於awr儲存期限所有的awr資料;
            2,這個特性重要,適用於資料庫使用整個awr保持期的資料比較度量指標的門限值;所以要使用自適應或自調整的門限;
            3,oracle自動預設維護一個系統定義的moving window baseline;
            4,其預設的視窗大小即當前awr的保持時間,8天;
            5,因為moving window baseline依賴於awr retention time,故先要變更它的值;
           
           
         3,baseline templates 基線模板
             1,有2個型別:單一和重複
             2,單一:適用於你預先想採集將來某個時間範圍的awr,建立單一的基線模板;
             3,重複:適用於重複執行(時間間隔)的採集任務;比如每週六:
                      新採集會覆蓋舊的採集資料
6,Adaptive Thresholds自調整或自適應門限
      1,檢測或監控效能問題
      2,根據基線計算出統計資訊自動化配置警告和嚴重警告門限;
      3,每週重計算一次門限
      4,基於不同的工作模式(對於OLTP和批處理)採用不同的門限值
     
      5,自適應門限的2種型別:
                 1,最大比例法:基於moving window baseline的最大統計值,計算其比例;
                 2,重要性級別法:基於moving window baseline配置的百分比;代表觀察法處理不合理的程度
                     百分比程度:
                               1,high(.95)--僅5%超過此值
                               2,very high(.99)--僅1%超過此值
                               3,severe(.999)僅1/1000超過此值     
                               4,extreme(.9999)僅1/100000超過此值
                 3,如指定severe or extreme,oracle通過內部計算配置門限值;在一些情況下,oracle
                    不會基於對應的級別建立門限值。
                 4,最大比例法適用於根據高峰時刻負荷的定義大小的系統;
                    當天工作負荷接近或超過之前高峰負荷的門限時,想接到警報;
                    比如:每秒產生的日誌可採用這種方法;
                 5,重要性級別法適用於系統正常運作其特性很穩定,而在效能變差時各個特徵變動很大;
                    比如:每秒事務響應時間;在正常情況下很不錯,但一旦效能變差,其指標值變化很大;
                   
awr空間佔用
 1,幾個影響的因素
     取樣的間隔
     活動會話數量
     歷史資料儲存期限
    
 2,如果減少awr空間佔用,會影響如下元件的發揮功能
     1,addm:automatic database diagnostic monitor
     2,sql tuning advisor
     3,,undo advisor
     4,segment advisor
    
管理awr
1,管理快照
2,管理基線
3,管理基線模板
4,傳輸awr資料
5,如何使用awr檢視
6,產生awr報告
7,產生awr比較報告
8,產生ash報告
9,使用ash報告

1,管理快照
   包括:建立快照
         刪除快照
         修改快照
   示例:
   --startup_time即資料庫啟動時間,取樣間隔為1小時,snap_level為快照的級別
   SQL> select snap_id,dbid,to_char(startup_time,'yyyymmdd hh24:mi:ss') as startup_time,to_char(BEGIN_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as BEGIN_INTERVAL_TIME,to_char(END_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as END_INTERVAL_TIME,snap_level from dba_hist_snapshot order by BEGIN_INTERVAL_TIME desc;
 
   SNAP_ID       DBID STARTUP_TIME      BEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_LEVEL
---------- ---------- ----------------- ------------------- ----------------- ----------
       657 1331266241 20130311 09:56:52 20130311 15:00:07   20130311 16:00:20          1
       656 1331266241 20130311 09:56:52 20130311 14:00:54   20130311 15:00:07          1
       655 1331266241 20130311 09:56:52 20130311 13:00:40   20130311 14:00:54          1
       654 1331266241 20130311 09:56:52 20130311 12:00:26   20130311 13:00:40          1
       653 1331266241 20130311 09:56:52 20130311 11:00:12   20130311 12:00:26          1
       652 1331266241 20130311 09:56:52 20130311 10:08:01   20130311 11:00:12          1
       651 1331266241 20130311 09:56:52 20130311 09:56:52   20130311 10:08:01          1
       650 1331266241 20130310 17:53:20 20130310 21:00:59   20130310 22:00:10          1
       649 1331266241 20130310 17:53:20 20130310 20:00:48   20130310 21:00:59          1
       648 1331266241 20130310 17:53:20 20130310 19:00:37   20130310 20:00:48          1
       647 1331266241 20130310 17:53:20 20130310 18:04:27   20130310 19:00:37          1
       646 1331266241 20130310 17:53:20 20130310 17:53:20   20130310 18:04:27          1
       645 1331266241 20130310 12:13:35 20130310 16:00:52   20130310 17:00:05          1
       644 1331266241 20130310 12:13:35 20130310 15:00:36   20130310 16:00:52          1
       643 1331266241 20130310 12:13:35 20130310 14:00:22   20130310 15:00:36          1
       642 1331266241 20130310 12:13:35 20130310 13:00:09   20130310 14:00:22          1
       641 1331266241 20130310 12:13:35 20130310 12:25:01   20130310 13:00:09          1
       640 1331266241 20130310 12:13:35 20130310 12:13:35   20130310 12:25:01          1
       639 1331266241 20130309 23:37:09 20130310 00:00:17   20130310 01:00:28          1
       638 1331266241 20130309 23:37:09 20130309 23:37:09   20130310 00:00:17          1    
                                                                                              
       --建立快照,                                                                                      
       SQL> exec dbms_workload_repository.create_snapshot();
 
          PL/SQL procedure successfully completed
          
          SQL>eselect snap_id,dbid,to_char(startup_time,'yyyymmdd hh24:mi:ss') as startup_time,to_char(BEGIN_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as BEGIN_INTERVAL_TIME,to_char(END_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as END_INTERVAL_TIME,snap_level from dba_hist_snapshot order by BEGIN_INTERVAL_TIME desc;
          
             SNAP_ID       DBID STARTUP_TIME      BEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_LEVEL
          ---------- ---------- ----------------- ------------------- ----------------- ----------
                 658 1331266241 20130311 09:56:52 20130311 16:00:20   20130311 16:04:03          1 --注意本行的end_interval_time,此時間間隔不足1 小時,即為手工建立
                 657 1331266241 20130311 09:56:52 20130311 15:00:07   20130311 16:00:20          1        
                
          --手工執行又產生一條快照      
          SQL> exec dbms_workload_repository.create_snapshot();
          
          PL/SQL procedure successfully completed
          
          SQL> select snap_id,dbid,to_char(startup_time,'yyyymmdd hh24:mi:ss') as startup_time,to_char(BEGIN_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as BEGIN_INTERVAL_TIME,to_char(END_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as END_INTERVAL_TIME,snap_level from dba_hist_snapshot order by BEGIN_INTERVAL_TIME desc;
          
             SNAP_ID       DBID STARTUP_TIME      BEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_LEVEL
          ---------- ---------- ----------------- ------------------- ----------------- ----------
                 659 1331266241 20130311 09:56:52 20130311 16:04:03   20130311 16:06:44          1
                 658 1331266241 20130311 09:56:52 20130311 16:00:20   20130311 16:04:03          1     
                
       --刪除快照
       SQL> select snap_id,dbid,to_char(startup_time,'yyyymmdd hh24:mi:ss') as startup_time,to_char(BEGIN_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as BEGIN_INTERVAL_TIME,to_char(END_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as END_INTERVAL_TIME,snap_level from dba_hist_snapshot where snap_id in (657,658,659) order by BEGIN_INTERVAL_TIME
            2  ;
          
             SNAP_ID       DBID STARTUP_TIME      BEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_LEVEL
          ---------- ---------- ----------------- ------------------- ----------------- ----------
                 657 1331266241 20130311 09:56:52 20130311 15:00:07   20130311 16:00:20          1
                 658 1331266241 20130311 09:56:52 20130311 16:00:20   20130311 16:04:03          1
                 659 1331266241 20130311 09:56:52 20130311 16:04:03   20130311 16:06:44          1
          
          SQL> exec dbms_workload_repository.drop_snapshot_range(low_snap_id => 657,high_snap_id => 659,dbid => 1331266241);
          
          PL/SQL procedure successfully completed
          
          SQL> select snap_id,dbid,to_char(startup_time,'yyyymmdd hh24:mi:ss') as startup_time,to_char(BEGIN_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as BEGIN_INTERVAL_TIME,to_char(END_INTERVAL_TIME,'yyyymmdd hh24:mi:ss') as END_INTERVAL_TIME,snap_level from dba_hist_snapshot where snap_id in (657,658,659) order by BEGIN_INTERVAL_TIME
            2  ;
          
             SNAP_ID       DBID STARTUP_TIME      BEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_LEVEL
          ---------- ---------- ----------------- ------------------- ----------------- ----------
         
          --修改快照
         
          --awr配置資訊
          SQL> select * from dba_hist_wr_control;
 
      DBID SNAP_INTERVAL                                                                   RETENTION                                                                       TOPNSQL
---------- ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- ----------
1331266241 +00000 01:00:00.0                                                               +00008 00:00:00.0                                                               DEFAULT
           --1,調節interval,retention,top sql引數值
             2,僅影響診斷工具的使用
             3,topsql指定針對每個sql標準(如:花費時間,cpu time,解析次數,佔用共享池等)永久儲存的最排列sql的數量
             4,配置這些引數僅影響awr sql收集的行為,不會改變統計重新整理級別即statistics_level和flush_level
            
             SQL> exec dbms_workload_repository.modify_snapshot_settings(topnsql => 100);
 
          PL/SQL procedure successfully completed
          
          SQL> select * from dba_hist_wr_control;
          
                DBID SNAP_INTERVAL                                                                   RETENTION                                                                       TOPNSQL
          ---------- ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- ----------
          1331266241 +00000 01:00:00.0                                                               +00008 00:00:00.0                                                                      100
           SQL> exec dbms_workload_repository.modify_snapshot_settings(topnsql => 'MAXIMUM');
          
          PL/SQL procedure successfully completed

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

相關文章