重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章将为大家详细讲解有关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如何创建基线”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。