1:查看、修改AWR報告快照數據的採樣間隔、保存策略 SQL> COL DBID FOR 999999999999SQL> COL SNAP_INTERVAL FOR A26SQL> COL RETENTION FOR A26SQL> COL TOPNSQL FOR A10SQL> select *... ...
1:查看、修改AWR報告快照數據的採樣間隔、保存策略
SQL> COL DBID FOR 999999999999
SQL> COL SNAP_INTERVAL FOR A26
SQL> COL RETENTION FOR A26
SQL> COL TOPNSQL FOR A10
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVAL RETENTION TOPNSQL
------------- -------------------------- -------------------------- ----------
3990839260 +00000 01:00:00.0 +00014 00:00:00.0 DEFAULT
SQL>
SNAP_INTERVAL=+00000 01:00:00.0 表示採樣間隔是1小時
RETENTION=+00014 00:00:00.0 表示採樣數據保留期限是14天
如上所示,快照採樣間隔為1小時一次,快照數據保留14天。修改AWR的快照採樣間隔、保存配置,改為30分鐘採集一次快照數據,快照資料庫保留7天。如下所示:
SQL> COL DBID FOR 999999999999
SQL> COL SNAP_INTERVAL FOR A26
SQL> COL RETENTION FOR A26
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVAL RETENTION TOPNSQL
------------- -------------------------- -------------------------- ----------
3990839260 +00000 01:00:00.0 +00014 00:00:00.0 DEFAULT
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>7*24*60);
PL/SQL procedure successfully completed.
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVAL RETENTION TOPNSQL
------------- -------------------------- -------------------------- ----------
3990839260 +00000 00:30:00.0 +00007 00:00:00.0 DEFAULT
SQL>
2:手動創建快照(Snapshots)
資料庫創建快照(Snapshots)一般是按Schedule定期創建的,預設一般一小時創建一個快照,只有當資料庫出現問題的時候,你才需要手工創建一個快照。以獲取那個時間段內的相關數據。
SQL> exec dbms_workload_repository.create_snapshot();
PL/SQL procedure successfully completed.
手工創建快照後,可以通過dba_hist_snapshot視圖查看創建的快照信息。
3:手動刪除快照(Snapshots)
--不指定DBID,預設當前實例DBID
SQL> exec dbms_workload_repository.drop_snapshot_range(61263,61274);
PL/SQL procedure successfully completed.
--指定DBID
SQL> exec dbms_workload_repository.drop_snapshot_range(7417,7429,3990839260);
PL/SQL procedure successfully completed.
4:創建基線(baseline)
一般來說當AWR自動維護快照時,如果定義過baseline,與baseline相關的快照不會被刪除,即使是過期的快照,這樣就相當於手動保留了一份統計數據的歷史信息,DBA可以在適當的時間將其與現有的快照進行對比,以生成相關的統計報表
SQL> COL BASELINE_NAME FOR A32;
SQL> SELECT DBID,BASELINE_NAME, START_SNAP_ID, END_SNAP_ID FROM DBA_HIST_BASELINE;
no rows selected
SQL> exec dbms_workload_repository.create_baseline(59806,59809,'20160726_07_11');
PL/SQL procedure successfully completed.
SQL> SELECT DBID,BASELINE_NAME, START_SNAP_ID, END_SNAP_ID FROM DBA_HIST_BASELINE;
DBID BASELINE_NAME START_SNAP_ID END_SNAP_ID
---------- -------------------------------- ------------- -----------
3990839260 20160726_07_11 59806 59809
SQL>
修改基線名稱
BEGIN
DBMS_WORKLOAD_REPOSITORY.rename_baseline(
old_baseline_name => 'old_name',
new_baseline_name => 'new_name');
END;
/
基線(baseline)是自Oracle 10g開始引入的,不過只包括了一些簡單的基線功能,創建一個基線允許保留指定範圍內的快照用於性能對比,與AWR保留策略無關,可以使用DBMS_WORKLOAD_REPOSITORY包來管理這個功能,在11g中,它被增強了。新增了許多功能。例如固定基線、移動視窗(Moving Window)基線等
5: 刪除基線(baseline)
首先查看基線設置,找到對應的baseline_name,然後刪除,過程如下所示:
SQL>SELECT * FROM DBA_HIST_BASELINE;
SQL> COL BASELINE_NAME FOR A32;
SQL> SELECT DBID,BASELINE_NAME, START_SNAP_ID, END_SNAP_ID FROM DBA_HIST_BASELINE;
DBID BASELINE_NAME START_SNAP_ID END_SNAP_ID
---------- -------------------------------- ------------- -----------
2179993557 20110112 12980 13004
2179993557 20100616 7959 7968
2179993557 20100818 9461 9485
2179993557 20101020 10964 10988
2179993557 20110119 13148 13172
2179993557 20101222 12476 12500
2179993557 20100602 7624 7632
SQL> exec dbms_workload_repository.drop_baseline('20110112',true);
PL/SQL procedure successfully completed.
刪除是如果指定了CASCADE參數為true,對應的snap也會被刪除。
6: 查看快照記錄信息
SELECT * FROM DBA_HIST_SNAPSHOT ORDER BY 1 DESC ;
SELECT SNAP_ID, DBID, INSTANCE_NUMBER, STARTUP_TIME,
BEGIN_INTERVAL_TIME, END_INTERVAL_TIME,
FLUSH_ELAPSED, SNAP_LEVEL, ERROR_COUNT
FROM WRM$_SNAPSHOT
WHERE STATUS = 0;
SELECT * FROM SYS.WRH$_ACTIVE_SESSION_HISTORY
7:導出、導入AWR快照數據
SQL> @?/rdbms/admin/awrextr.sql
SQL> @?/rdbms/admin/awrload.sql
8:刪除導入的AWR快照數據。
如果要刪除導入的awr數據,可以使用下麵腳本進行刪除。
exec dbms_swrf_internal.unregister_database(dbid);
sql> exec dbms_swrf_internal.unregister_database(3990839260);
dbms_workload_repository: