OracleAWR刪除曆史快照說明

來源:互聯網
上載者:User

標籤:

測試時,發現無法產生新快照,查看系統時間為10月26,但是已經產生快照為12月1號了。

此時的解決辦法,就是刪除現有的快照。

 

轉http://itlab.idcquan.com/Oracle/backup/947118_2.html

 一。 AWR 概述

  之前整理過一篇AWR 的說明的文檔:

  Oracle AWR(Automatic Workload Repository) 說明

  http://blog.csdn.net/tianlesoftware/article/details/4682300

  從Oracle 10g 開始,Oracle 推出一個工具:AWR(Automatic Workload Repository),並建議用AWR 代替9i 的Statspack.

  AWR 實質上是一個 Oracle 的內建工具,它採集與效能相關的統計資料,並從那些統計資料中匯出效能量度,以跟蹤潛在的問題。

  AWR的快照由一個MMON的後台進程及其從進程自動地每小時採集一次。為了節省空間的,在Oracle 10g中快照會保留7天,11g的快照保留8天,超過的會自動刪除,快照頻率和保留時間都可以由使用者修改。

  AWR 使用幾個表來儲存採集的統計資料,所有的表都儲存在新的名稱為 SYSAUX 的特定資料表空間中的SYS模式下,並且以 WRM$_* 和 WRH$_* 的格式命名:

  (1)WRM$_*類表格儲存體中繼資料資訊(如檢查的資料庫和採集的快照)

  (2)WRH$_*類儲存實際採集的統計資料。

  H 代表"曆史資料 (historical)"而 M 代表"中繼資料 (metadata)".

  在這些表上構建了幾種帶首碼 DBA_HIST_ 的視圖,這些視圖可以用來編寫您自己的效能診斷工具。視圖的名稱直接與表相關;例如,視圖 DBA_HIST_SYSMETRIC_SUMMARY 是在WRH$_SYSMETRIC_SUMMARY 表上構建的。

  二。 AWR 快照的刪除

  2.1 為什麼要刪除AWR 快照?

  預設情況下,對於資料庫自身產生的AWR 報告,會保留7天或8天。

  SQL> select dbid, retention from dba_hist_wr_control;

  DBID RETENTION

  -------------------------------------------------------------------------------------

  879543530 +00008 00:00:00.0

  這個是我11g的庫,顯示為8天,如果是Oracle 10g,則會保留7天。

  AWR 快照也可以從其他的資料庫中匯入,我們這裡看一下:

  SQL> select dbid, retention from dba_hist_wr_control;

  DBID RETENTION

  -------------------------------------------------------------------------------

  877621333 +40150 00:00:00.0

  879543530 +00008 00:00:00.0

  如果是從其他庫匯入的快照,在10g以後會儲存110年(40150/365),這部分資料不會永久刪除。

  --AWR匯出指令碼:

  SQL> @?/rdbms/admin/awrextr.sql

  --AWR匯入指令碼:

  SQL> @?/rdbms/admin/awrload.sql

  另一個很重要的原因,就是有時候自動快照不能自動收集,而手工建立快照又可以成功,對於這種問題的解決方案就是把之前的快照清空掉。

  2.2 刪除AWR 快照資料

  2.2.1 使用dbms_workload_repository 包來刪除

  2.2.1.1 刪除原生AWR 快照

  SQL> select dbid, retention from dba_hist_wr_control;

  DBID RETENTION

  ---------- --------------------

  879543530 +00008 00:00:00.0

  SQL> select min(snap_id), max(snap_id) from dba_hist_snapshot where dbid = 879543530;

  MIN(SNAP_ID)MAX(SNAP_ID)

  ------------------------

  161 176

  SQL> exec dbms_workload_repository.drop_snapshot_range(161, 176, 879543530)

  PL/SQL proceduresuccessfully completed.

  SQL> select *from dba_hist_snapshot where dbid = 879543530;

  no rows selected

  2.2.1.2 刪除其他執行個體的快照

  SQL> select dbid, retention fromdba_hist_wr_control;

  DBID RETENTION

  ---------- ---------------------------------------------------------------------

  877621333 +40150 00:00:00.0

  879543530 +00008 00:00:00.0

  SQL> select min(snap_id), max(snap_id)from dba_hist_snapshot where dbid = 877621333;

  MIN(SNAP_ID) MAX(SNAP_ID)

  ------------ ------------

  160 192

  SQL> execdbms_workload_repository.drop_snapshot_range(160, 170, 877621333)

  PL/SQL procedure successfully completed.

  SQL> select min(snap_id), max(snap_id) from dba_hist_snapshot where dbid =877621333;

  MIN(SNAP_ID) MAX(SNAP_ID)

  ------------ ------------

  171 192

  SQL>

  刪除成功。

  2.2.2 使用dbms_swrf_internal包來刪除

  2.2.2.1 刪除其他資料庫匯入的AWR

  SQL> select dbid, retention fromdba_hist_wr_control;

  DBID RETENTION

  -------------------------------------------------------------------------------

  877621333 +40150 00:00:00.0

  879543530 +00008 00:00:00.0

  SQL> select min(snap_id), max(snap_id)from dba_hist_snapshot where dbid = 877621333;

  MIN(SNAP_ID) MAX(SNAP_ID)

------------ ------------

  160 192

  SQL> exec dbms_swrf_internal.unregister_database(877621333)

  PL/SQL procedure successfully completed.

  SQL> select min(snap_id), max(snap_id)from dba_hist_snapshot where dbid = 877621333;

  MIN(SNAP_ID) MAX(SNAP_ID)

  ------------ ------------

  SQL> select dbid, retention fromdba_hist_wr_control;

  DBID RETENTION

  -------------------------------------------------------------------------------

  879543530 +00008 00:00:00.0

  SQL>

  dbms_swrf_internal.unregister_database 會把所有的快照直接幹掉,與我們上節中的刪除是不同的效果。

  2.2.2.2 刪除原生AWR

  我們之前把快照清空了,所以沒有結果:

  SQL> select * from dba_hist_snapshotwhere dbid = 879543530;

  no rows selected

  SQL> executedbms_workload_repository.create_snapshot();

  PL/SQL procedure successfully completed.

  SQL> executedbms_workload_repository.create_snapshot();

  PL/SQL procedure successfully completed.

  SQL> executedbms_workload_repository.create_snapshot();

  PL/SQL procedure successfully completed.

  SQL> executedbms_workload_repository.create_snapshot();

  PL/SQL procedure successfully completed.

  --現在又有快照了:

  SQL> select min(snap_id), max(snap_id)from dba_hist_snapshot where dbid = 879543530;

  MIN(SNAP_ID) MAX(SNAP_ID)

  ------------ ------------

  177 180

  --刪除快照:

  SQL> exec dbms_swrf_internal.unregister_database(879543530)

  BEGINdbms_swrf_internal.unregister_database(879543530); END;

  *

  ERROR at line 1:

  ORA-13521: Unregister operation on localDatabase id (879543530) not allowed

  ORA-06512: at"SYS.DBMS_SWRF_INTERNAL", line 99

  ORA-06512: at line 1

  這裡直接提示,dbms_swrf_internal.unregister_database不能對本地的資料庫使用。所以如果本地的資料庫,就只能使用dbms_workload_repository包了。

  2.2.3 小結

  dbms_workload_repository:

  可以刪除本地和其他資料庫的快照,可以選擇不同的快照來進行刪除。

  dbms_swrf_internal:

  只能對其他資料庫的快照來進行操作,會把整個快照unregister掉。

OracleAWR刪除曆史快照說明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.