最近突然发现俺还一直停留在使用一些oracle8i, 9i的方法进行Oracle的诊断和调优,虽然也比较有成效,但是的确是比较落后,不够时髦,因此晚上抽出时间学习了一下awr,发现可以利用DBMS_WORKLOAD_REPOSITORY来操作awr的方方面面。
该包的定义:
21:11:09 SQL> desc dbms_workload_repository
FUNCTION ASH_REPORT_HTML RETURNS AWRRPT_HTML_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
L_DBID NUMBER IN
L_INST_NUM NUMBER IN
L_BTIME DATE IN
L_ETIME DATE IN
L_OPTIONS NUMBER IN DEFAULT
L_SLOT_WIDTH NUMBER IN DEFAULT
L_SID NUMBER IN DEFAULT
L_SQL_ID VARCHAR2 IN DEFAULT
L_WAIT_CLASS VARCHAR2 IN DEFAULT
L_SERVICE_HASH NUMBER IN DEFAULT
L_MODULE VARCHAR2 IN DEFAULT
L_ACTION VARCHAR2 IN DEFAULT
L_CLIENT_ID VARCHAR2 IN DEFAULT
L_PLSQL_ENTRY VARCHAR2 IN DEFAULT
FUNCTION ASH_REPORT_TEXT RETURNS AWRRPT_TEXT_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
L_DBID NUMBER IN
L_INST_NUM NUMBER IN
L_BTIME DATE IN
L_ETIME DATE IN
L_OPTIONS NUMBER IN DEFAULT
L_SLOT_WIDTH NUMBER IN DEFAULT
L_SID NUMBER IN DEFAULT
L_SQL_ID VARCHAR2 IN DEFAULT
L_WAIT_CLASS VARCHAR2 IN DEFAULT
L_SERVICE_HASH NUMBER IN DEFAULT
L_MODULE VARCHAR2 IN DEFAULT
L_ACTION VARCHAR2 IN DEFAULT
L_CLIENT_ID VARCHAR2 IN DEFAULT
L_PLSQL_ENTRY VARCHAR2 IN DEFAULT
FUNCTION AWR_DIFF_REPORT_HTML RETURNS AWRRPT_HTML_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
DBID1 NUMBER IN
INST_NUM1 NUMBER IN
BID1 NUMBER IN
EID1 NUMBER IN
DBID2 NUMBER IN
INST_NUM2 NUMBER IN
BID2 NUMBER IN
EID2 NUMBER IN
FUNCTION AWR_DIFF_REPORT_TEXT RETURNS AWRDRPT_TEXT_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
DBID1 NUMBER IN
INST_NUM1 NUMBER IN
BID1 NUMBER IN
EID1 NUMBER IN
DBID2 NUMBER IN
INST_NUM2 NUMBER IN
BID2 NUMBER IN
EID2 NUMBER IN
FUNCTION AWR_REPORT_HTML RETURNS AWRRPT_HTML_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
L_DBID NUMBER IN
L_INST_NUM NUMBER IN
L_BID NUMBER IN
L_EID NUMBER IN
L_OPTIONS NUMBER IN DEFAULT
FUNCTION AWR_REPORT_TEXT RETURNS AWRRPT_TEXT_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
L_DBID NUMBER IN
L_INST_NUM NUMBER IN
L_BID NUMBER IN
L_EID NUMBER IN
L_OPTIONS NUMBER IN DEFAULT
FUNCTION AWR_SQL_REPORT_HTML RETURNS AWRRPT_HTML_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
L_DBID NUMBER IN
L_INST_NUM NUMBER IN
L_BID NUMBER IN
L_EID NUMBER IN
L_SQLID VARCHAR2 IN
L_OPTIONS NUMBER IN DEFAULT
FUNCTION AWR_SQL_REPORT_TEXT RETURNS AWRSQRPT_TEXT_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
L_DBID NUMBER IN
L_INST_NUM NUMBER IN
L_BID NUMBER IN
L_EID NUMBER IN
L_SQLID VARCHAR2 IN
L_OPTIONS NUMBER IN DEFAULT
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
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
PROCEDURE CREATE_SNAPSHOT
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
FLUSH_LEVEL VARCHAR2 IN DEFAULT
FUNCTION CREATE_SNAPSHOT RETURNS NUMBER
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
FLUSH_LEVEL VARCHAR2 IN DEFAULT
PROCEDURE DROP_BASELINE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
BASELINE_NAME VARCHAR2 IN
CASCADE BOOLEAN IN DEFAULT
DBID NUMBER IN DEFAULT
PROCEDURE DROP_SNAPSHOT_RANGE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
LOW_SNAP_ID NUMBER IN
HIGH_SNAP_ID NUMBER IN
DBID NUMBER IN DEFAULT
PROCEDURE MODIFY_SNAPSHOT_SETTINGS
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
RETENTION NUMBER IN DEFAULT
INTERVAL NUMBER IN DEFAULT
TOPNSQL NUMBER IN DEFAULT
DBID NUMBER IN DEFAULT
PROCEDURE MODIFY_SNAPSHOT_SETTINGS
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
RETENTION NUMBER IN DEFAULT
INTERVAL NUMBER IN DEFAULT
TOPNSQL VARCHAR2 IN
DBID NUMBER IN DEFAULT
1. 创建一个快照:
BEGIN
DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();
END;
/
创建出来的快照信息,可以通过DBA_HIST_SNAPSHOT数据字典获得。其结构如下:
21:28:01 SQL> desc dba_hist_snapshot
Name Null? Type
----------------------------------------- -------- ----------------------------
SNAP_ID NOT NULL NUMBER
DBID NOT NULL NUMBER
INSTANCE_NUMBER NOT NULL NUMBER
STARTUP_TIME NOT NULL TIMESTAMP(3)
BEGIN_INTERVAL_TIME NOT NULL TIMESTAMP(3)
END_INTERVAL_TIME NOT NULL TIMESTAMP(3)
FLUSH_ELAPSED INTERVAL DAY(5) TO SECOND(1)
SNAP_LEVEL NUMBER
ERROR_COUNT NUMBER
2. 删除快照
可以通过DROP_SNAPSHOT_RANGE存储过程来删除一些不用的快照:
BEGIN
DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE (low_snap_id => 15,
high_snap_id => 20, dbid => 2036468763);
END;
/
3. 修改抓取快照的设置
可以使用MODIFY_SNAPSHOT_SETTINGS存储过程来修改设置,如下面的语句将快照的保留的时间设置为一个月,每隔30分钟抓取一次快照:
BEGIN
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS( retention => 43200,
interval => 30, topnsql => 100, dbid => 2036468763);
END;
/
可以通过查看 DBA_HIST_WR_CONTROL
数据字典来查看当前的snapshot的设置,以下是该表的结构以及相关的数据,
21:40:10 SQL> desc dba_hist_wr_control
Name Null? Type
----------------------------------------- -------- ----------------------------
DBID NOT NULL NUMBER
SNAP_INTERVAL NOT NULL INTERVAL DAY(5) TO SECOND(1)
RETENTION NOT NULL INTERVAL DAY(5) TO SECOND(1)
TOPNSQL VARCHAR2(10)
21:42:31 SQL> select * from dba_hist_wr_control;
DBID
----------
SNAP_INTERVAL
---------------------------------------------------------------------------
RETENTION
---------------------------------------------------------------------------
TOPNSQL
----------
2036468763
+00000 01:00:00.0
+00007 00:00:00.0
DEFAULT