使用 DBMS_WORKLOAD_REPOSITORY 包管理 baseline
1. 创建 baseline
--在 DBA_HIST_SNAPSHOT 视图中查看现有的快照来确定要使用的快照范围。
select snap_id,dbid,BEGIN_INTERVAL_TIME,END_INTERVAL_TIME,SNAP_LEVEL from dba_hist_snapshot;
SNAP_ID DBID BEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_LEVEL
---------- ---------- ------------------------------ ------------------------------ ----------
21 220853307 04-MAR-13 02.00.49.845 PM 04-MAR-13 03.00.58.970 PM 1
22 220853307 04-MAR-13 03.00.58.970 PM 04-MAR-13 04.00.08.328 PM 1
23 220853307 04-MAR-13 04.00.08.328 PM 04-MAR-13 05.00.17.091 PM 1
24 220853307 04-MAR-13 05.00.17.091 PM 04-MAR-13 06.00.26.037 PM 1
25 220853307 04-MAR-13 06.00.26.037 PM 04-MAR-13 07.00.35.429 PM 1
26 220853307 04-MAR-13 07.00.35.429 PM 04-MAR-13 08.00.44.059 PM 1
27 220853307 06-MAR-13 10.30.05.000 PM 06-MAR-13 10.40.56.516 PM 1
28 220853307 07-MAR-13 09.08.50.000 PM 07-MAR-13 09.19.47.771 PM 1
29 220853307 07-MAR-13 09.19.47.771 PM 07-MAR-13 10.00.53.958 PM 1
30 220853307 07-MAR-13 10.00.53.958 PM 07-MAR-13 10.59.09.642 PM 1
31 220853307 07-MAR-13 10.59.09.642 PM 08-MAR-13 12.00.13.313 AM 1
32 220853307 08-MAR-13 10.20.00.000 AM 08-MAR-13 10.30.57.436 AM 1
--使用 CREATE_BASELINE 存储过程创建一个 baseline。
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(
start_snap_id IN NUMBER,
end_snap_id IN NUMBER,
baseline_name IN VARCHAR2,
dbid IN NUMBER DEFAULT NULL,
expiration IN NUMBER DEFAULT NULL);
BEGIN
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE (start_snap_id => 21,
end_snap_id => 25, baseline_name => 'peak baseline',
dbid => 220853307, expiration => 30);
END;
/
--21 是起始的 snapshot 序列号,25 是结束 snapshot 序列号。expiration => 30 表示该 baseline 将在30天
--后自动删除
--创建 baseline 时,系统会自动分配一个唯一的 baseline ID 给新建的 baseline。可以通过 DBA_HIST_BASELINE 视图查看。
select dbid,baseline_id,baseline_name,EXPIRATION,CREATION_TIME from dba_hist_baseline;
DBID BASELINE_ID BASELINE_NAME EXPIRATION CREATION_TIME
---------- ----------- -------------------- ---------- -------------------
220853307 1 peak baseline 30 2013-03-08 11:03:03
220853307 0 SYSTEM_MOVING_WINDOW 2013-03-02 14:23:12
2.删除 baseline
BEGIN
DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE (baseline_name => 'peak baseline',
cascade => FALSE, dbid => 3310949047);
END;
/
--cascade 参数设置为 FALSE,指定只删除。将此参数设置为 TRUE 指定删除与该 baseline 相关联的所有快照。
3.重命名 baseline
--查询原 baseline 的名称
select dbid,baseline_id,baseline_name,EXPIRATION,CREATION_TIME from dba_hist_baseline;
DBID BASELINE_ID BASELINE_NAME EXPIRATION CREATION_TIME
---------- ----------- -------------------- ---------- -------------------
220853307 1 peak baseline 30 2013-03-08 11:03:03
220853307 0 SYSTEM_MOVING_WINDOW 2013-03-02 14:23:12
--使用 rename_baseline 存储过程重命名 baseline
BEGIN
DBMS_WORKLOAD_REPOSITORY.RENAME_BASELINE (
old_baseline_name => 'peak baseline',
new_baseline_name => 'peak maomi',
dbid => 220853307);
END;
/
11:44:49 sys@PROD> select dbid,baseline_id,baseline_name,EXPIRATION,CREATION_TIME from dba_hist_baseline;
DBID BASELINE_ID BASELINE_NAME EXPIRATION CREATION_TIME
---------- ----------- -------------------- ---------- -------------------
220853307 1 peak maomi 30 2013-03-08 11:03:03
220853307 0 SYSTEM_MOVING_WINDOW 2013-03-02 14:23:12
4.显示 baseline 度量标准
如果使用了自适应阈值,则 baseline 将包含数据库用于计算度量阈值的 AWR 数据。SELECT_BASELINE_METRICS 函数
baseline 期间的度量值的摘要统计信息。
11:44:57 sys@PROD> select dbid,baseline_id,baseline_name,EXPIRATION,CREATION_TIME from dba_hist_baseline;
DBID BASELINE_ID BASELINE_NAME EXPIRATION CREATION_TIME
---------- ----------- -------------------- ---------- -------------------
220853307 1 peak maomi 30 2013-03-08 11:03:03
220853307 0 SYSTEM_MOVING_WINDOW 2013-03-02 14:23:12
-------
BEGIN
DBMS_WORKLOAD_REPOSITORY.SELECT_BASELINE_METRICS (
baseline_name => 'peak maomi',
dbid => 220853307,
instance_num => '1');
END;
/
5. 修改默认 moving window baseline 的默认 window size
12:27:34 sys@PROD> select DBID,BASELINE_ID,BASELINE_NAME,MOVING_WINDOW_SIZE from dba_hist_baseline;
DBID BASELINE_ID BASELINE_NAME MOVING_WINDOW_SIZE
---------- ----------- -------------------- ------------------
220853307 1 peak maomi
220853307 0 SYSTEM_MOVING_WINDOW 8
BEGIN
DBMS_WORKLOAD_REPOSITORY.MODIFY_BASELINE_WINDOW_SIZE (
window_size => 30,
dbid => 220853307);
END;
/
BEGIN
*
ERROR at line 1:
ORA-13541: system moving window baseline size (2592000) greater than retention (691200)
ORA-06512: at "SYS.DBMS_WORKLOAD_REPOSITORY", line 686
ORA-06512: at line 2
报错是因为设置的窗口大小超过了当前 AWR 保留期限,所以必须先增加 AWR 保留期限,方法如下:
BEGIN
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS( retention => 43200,
interval => 30, topnsql => 100, dbid => 220853307);
END;
/
转载请注明出处及原文链接:
http://blog.csdn.net/xiangsir/article/details/8654275