您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關oracle 11g如何創建基線,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
性能優化時大體有如下兩種評估方式:如果希望知道性能度量值指示服務器接近容量限制,則應設置絕對值;但是如果希望知道今天的性能與上周(或者上個月)同一時間的性能之間的差異,則當前性能必須與基線進行比較,基線是某個時段內生成的一組快照,按照統計學對這些快照進行了分組,以便獲得一組隨時間變化的基線值,可以以任何時段快照采樣來做基線,只不過一般情況下我們大多會選擇系統正常時段的快照來做基線。
基線在oracle 10g中就出現了,而在oracle database 11g進一步增強了自動工作量資料檔案庫基線:
1 即用型移動窗口基線,可通過該基線指定自適應閥值
2 使用基線模板安排基線的創建操作
3 重命名基線
4 設置基線的到期日期
AWR baseline是指一個特定時間段內的性能數據,保留這些數據是為了在性能問題產生時與其他類似的工作負載時間段進行比較:
fixed baseline:fixed baseline表示的是您制定的一個固定的、連續的時間段
moving window baseline:表示的是war保留期內存在的所有war數據
Baseline template:您可以使用baseline template創建將來某個連續時間段的baseline,oracle中有兩種baseline模板分別是single和repeating
創建fixed baseline:
SQL> begin
2 dbms_workload_repository.create_baseline(
3 start_snap_id=>1510,
4 end_snap_id=>1511,
5 baseline_name=>'test_baseline');
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> select dbid,baseline_name,start_snap_id,end_snap_id,MOVING_WINDOW_SIZE,EXPIRATION from dba_hist_baseline;
DBID BASELINE_NAME START_SNAP_ID END_SNAP_ID MOVING_WINDOW_SIZE EXPIRATION
---------- ---------------------------------------------------------------- ------------- ----------- ------------------ ----------
4257181262 test_baseline 1510 1511
4257181262 SYSTEM_MOVING_WINDOW 1515 1591 8
創建baseline的procedure和function
根據snap_id創建:
PROCEDURE CREATE_BASELINE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
START_SNAP_ID NUMBER IN
END_SNAP_ID NUMBER IN
BASELINE_NAME VARCHAR2 IN
DBID NUMBER IN DEFAULT
EXPIRATION NUMBER IN DEFAULT
FUNCTION CREATE_BASELINE RETURNS NUMBER
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
START_SNAP_ID NUMBER IN
END_SNAP_ID NUMBER IN
BASELINE_NAME VARCHAR2 IN
DBID NUMBER IN DEFAULT
EXPIRATION NUMBER IN DEFAULT
根據時間創建:
PROCEDURE CREATE_BASELINE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
START_TIME DATE IN
END_TIME DATE IN
BASELINE_NAME VARCHAR2 IN
DBID NUMBER IN DEFAULT
EXPIRATION NUMBER IN DEFAULT
FUNCTION CREATE_BASELINE RETURNS NUMBER
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
START_TIME DATE IN
END_TIME DATE IN
BASELINE_NAME VARCHAR2 IN
DBID NUMBER IN DEFAULT
EXPIRATION NUMBER IN DEFAULT
還可以刪除和重命名baseline:
SQL> begin
2 dbms_workload_repository.drop_baseline(
3 baseline_name=>'test_baseline',
4 cascade=>true);
5 end;
6 /
PL/SQL procedure successfully completed.
在oracle 11g中系統已經默認創建moving window baseline:
SQL> select dbid,baseline_name,start_snap_id,end_snap_id,MOVING_WINDOW_SIZE,EXPIRATION from dba_hist_baseline;
DBID BASELINE_NAME START_SNAP_ID END_SNAP_ID MOVING_WINDOW_SIZE EXPIRATION
---------- ---------------------------------------------------------------- ------------- ----------- ------------------ ----------
4257181262 SYSTEM_MOVING_WINDOW 1515 1591 8
drop baseline時如果指定cascade=>true,將把baseline對應的snap也級聯刪除了
oracle database會自動維護系統定義的moving window baseline,系統定義的moving window baseline的默認窗口大小就是當前的AWR保留期,如果打算使用自適應閥值,請考慮使用更長的移動窗口,比如30天,以便精確的計算閥值。移動窗口的大小調整為小于或等于AWR的保留天數,因為要增加移動窗口的大小,必須要先增加相應的AWR保留期限。
調整awr的保留周期:
SQL> exec dbms_workload_repository.modify_snapshot_settings(retention=>43200);
PL/SQL procedure successfully completed.
SQL> select retention from dba_hist_wr_control;
RETENTION
---------------------------------------------------------------------------
+00030 00:00:00.0
SQL> select baseline_id,baseline_name,moving_window_size from dba_hist_baseline;
BASELINE_ID BASELINE_NAME MOVING_WINDOW_SIZE
----------- ---------------------------------------------------------------- ------------------
0 SYSTEM_MOVING_WINDOW 8
SQL> exec dbms_workload_repository.modify_baseline_window_size(window_size=>30);
PL/SQL procedure successfully completed.
SQL> select baseline_id,baseline_name,moving_window_size from dba_hist_baseline;
BASELINE_ID BASELINE_NAME MOVING_WINDOW_SIZE
----------- ---------------------------------------------------------------- ------------------
0 SYSTEM_MOVING_WINDOW 30
基線模板:基線模板允許定義可能在將來要捕捉的基線,create_baseline_template存儲過程定義單一基線或重復基線的捕捉,創建單一基線模板與創建基于時間的基線類似,除了將來的時間外。
single基線模板:
PROCEDURE CREATE_BASELINE_TEMPLATE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
START_TIME DATE IN
END_TIME DATE IN
BASELINE_NAME VARCHAR2 IN
TEMPLATE_NAME VARCHAR2 IN
EXPIRATION NUMBER IN DEFAULT
DBID NUMBER IN DEFAULT
SQL> exec DBMS_WORKLOAD_REPOSITORY.create_baseline_template(start_time=>TO_DATE('09-MAR-2016 00:00', 'DD-MON-YYYY HH24:MI'),end_time=>TO_DATE('16-MAR-2016 05:00', 'DD-MON-YYYY HH24:MI'),baseline_name=>'09_11_14_BS1',template_name =>'09_11_14_TP1',expiration=> 10);
PL/SQL procedure successfully completed.
SQL> select dbid,template_name,template_type,baseline_name_prefix,start_time,end_time,duration,expiration from dba_hist_baseline_template;
DBID TEMPLATE_NAME TEMPLATE_ BASELINE_NAME_PREFIX START_TIME END_TIME DURATION EXPIRATION
---------- ------------------------------ --------- ------------------------------ ------------------- ------------------- ---------- ----------
4257181262 09_11_14_TP1 SINGLE 09_11_14_BS1 2016-03-09 00:00:00 2016-03-16 05:00:00 10
重復基線模板稍微有點不同,因為它需要調度信息,start_time和end_time參數分別在模板激活和釋放時定義,day_of_week、hour_in_day和duration定義產生基線的日期、時間和持續時間,因為模板會產生多個基線,基線名是以baseline_name_prefix開始的。
repeat基線模板:
PROCEDURE CREATE_BASELINE_TEMPLATE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
DAY_OF_WEEK VARCHAR2 IN
HOUR_IN_DAY NUMBER IN
DURATION NUMBER IN
START_TIME DATE IN
END_TIME DATE IN
BASELINE_NAME_PREFIX VARCHAR2 IN
TEMPLATE_NAME VARCHAR2 IN
EXPIRATION NUMBER IN DEFAULT
DBID NUMBER IN DEFAULT
exec DBMS_WORKLOAD_REPOSITORY.create_baseline_template(day_of_week=>'MONDAY',hour_in_day=>0,duration=>5,start_time=>SYSDATE,end_time=>ADD_MONTHS(SYSDATE, 6),baseline_name_prefix =>'monday_morning_bl',template_name=>'monday_morning_tp',expiration=> NULL);
SQL> select dbid,TEMPLATE_NAME,TEMPLATE_TYPE,BASELINE_NAME_PREFIX,START_TIME,END_TIME,DAY_OF_WEEK,HOUR_IN_DAY,DURATION,EXPIRATION,REPEAT_INTERVAL from dba_hist_baseline_template;
DBID TEMPLATE_NAME TEMPLATE_ BASELINE_NAME_PREFIX START_TIME END_TIME DAY_OF_WE HOUR_IN_DAY DURATION EXPIRATION
---------- ------------------------------ --------- ------------------------------ ------------------- ------------------- --------- ----------- ---------- ----------
REPEAT_INTERVAL
--------------------------------------------------------------------------------
4257181262 09_11_14_TP1 SINGLE 09_11_14_BS1 2016-03-09 00:00:00 2016-03-16 05:00:00 10
4257181262 monday_morning_tp REPEATING monday_morning_bl 2016-03-15 02:54:55 2016-09-15 02:54:55 MONDAY 0 5
FREQ=WEEKLY;INTERVAL=1;BYDAY=MON;BYHOUR=0;BYMINUTE=0;BYSECOND=0
上面介紹了基線,那么如何來使用基線和指定時段的快照做awr數據對比了,其實Oracle為我們提供出AWR Compare Period Report來方便實現指定時段的awr數據對比。
由于基線又由于可以一直保存在awr快照中,DBA做性能分析時則可以利用基線和故障時段的awr做對比,更進一步的分析數據庫的性能趨勢變化,下面簡單的來做一個AWR數據時段對比:
SQL> select dbid,min(snap_id),max(snap_id) from dba_hist_snapshot group by dbid;
DBID MIN(SNAP_ID) MAX(SNAP_ID)
---------- ------------ ------------
4257181262 1508 1669
這里創建snap_id 1656到1657的基線
SQL> begin
2 dbms_workload_repository.create_baseline(
3 start_snap_id=>1656,
4 end_snap_id=>1657,
5 baseline_name=>'test_baseline');
6 end;
7 /
PL/SQL procedure successfully completed.
刪除大部分snapshot
SQL> exec dbms_workload_repository.drop_snapshot_range(1508, 1667, 4257181262);
PL/SQL procedure successfully completed.
SQL> select snap_id,begin_interval_time,end_interval_time from dba_hist_snapshot where dbid=4257181262;
SNAP_ID BEGIN_INTERVAL_TIME END_INTERVAL_TIME
---------- --------------------------------------------------------------------------- ---------------------------------------------------------------------------
1669 15-MAR-16 10.23.42.387 PM 15-MAR-16 11.10.41.380 PM
1656 11-MAR-16 10.00.33.158 PM 14-MAR-16 08.40.27.499 PM
1657 14-MAR-16 08.40.27.499 PM 14-MAR-16 10.00.35.439 PM
1668 15-MAR-16 08.41.44.009 PM 15-MAR-16 10.23.42.387 PM
這里也驗證了之前awr baseline的部分對應的snapshot并不會被awr保留策略或者手動刪除awr而刪除掉。
接下來使用awrddrpt.sql腳本來生成兩個awr的對比數據:
SQL> @awrddrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Id DB Name Inst Num Inst Num Instance
----------- ----------- ------------ -------- -------- ------------
4257181262 4257181262 ORA11G 1 1 ora11g
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: html
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
2350429211 1 TLINK tlink ylqz_s
* 4257181262 1 ORA11G ora11g redhat-ora
Database Id and Instance Number for the First Pair of Snapshots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using 4257181262 for Database Id for the first pair of snapshots
Using 1 for Instance Number for the first pair of snapshots
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing
without
specifying a number lists all completed snapshots.
Enter value for num_days: 3
Listing the last 3 days of Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
ora11g ORA11G 1656 14 Mar 2016 20:40 1
1657 14 Mar 2016 22:00 1
1668 15 Mar 2016 22:23 1
1669 15 Mar 2016 23:10 1
Specify the First Pair of Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1656
First Begin Snapshot Id specified: 1656
Enter value for end_snap: 1657
First End Snapshot Id specified: 1657
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
2350429211 1 TLINK tlink ylqz_s
* 4257181262 1 ORA11G ora11g redhat-ora
Database Id and Instance Number for the Second Pair of Snapshots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using 4257181262 for Database Id for the second pair of snapshots
Using 1 for Instance Number for the second pair of snapshots
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing
without
specifying a number lists all completed snapshots.
Enter value for num_days2: 3
Listing the last 3 days of Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
ora11g ORA11G 1656 14 Mar 2016 20:40 1
1657 14 Mar 2016 22:00 1
1668 15 Mar 2016 22:23 1
1669 15 Mar 2016 23:10 1
Specify the Second Pair of Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap2: 1668
Second Begin Snapshot Id specified: 1668
Enter value for end_snap2: 1669
Second End Snapshot Id specified: 1669
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrdiff_1_1656_1_1668.html To use this name,
press
to continue, otherwise enter an alternative.
Enter value for report_name: /home/oracle/awr0316.hmtl
關于“oracle 11g如何創建基線”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。