自動化維護任務 – Automated Maintenance Task


轉自:http://os2ora.com/automated-maintenance-task/

這是11g引入的一套新的自動化機制。Oracle的官方文檔大而全,不過想理清楚里面的來龍去脈可不是一件容易的事情。

不過下面幾點知識要點是應該記住的。
1. Oracle有三個已定義好的automated maintenance tasks.

  1. Automatic Optimizer Statistics Collection—用於收集各種數據庫對象的統計信息。這里又有三種模式:
    • ‘ALL’ – Statistics are collected for all objects in the system
    • ‘ORACLE’ – Statistics are collected for all Oracle owned objects
    • ‘AUTO’ – Oracle decides for which objects to collect statistics
    • 可以通過以下API進行設置
            DBMS_STATS.SET_GLOBAL_PREFS (
              pname VARCHAR2,
              pval VARCHAR2);

        pname為”AUTOSTATS_TARGET”,pval為以上三個值之一。

  2. Automatic Segment Advisor—Identifies segments that have space available for reclamation, and makes recommendations on how to defragment those segments. You can also run the Segment Advisor manually to obtain more up-to-the-minute recommendations or to obtain recommendations on segments that the Automatic Segment Advisor did not examine for possible space reclamation.
  3. Automatic SQL Tuning Advisor—Examines the performance of high-load SQL statements, and makes recommendations on how to tune those statements. You can configure this advisor to automatically implement SQL profile recommendations.

2. 這些automated maintenace tasks在maintenance windows里得到執行。同樣,Oracle已經定義好的7個windows,對應每周的每一天。周一到周五是從22:00到次日的02:00,周六和周日是從06:00到次日的02:00。

3. 如果不想這些automated maintenance tasks在一些windows里不被執行,或者完全不希望執行這些tasks。可以通過下面的API。

DBMS_AUTO_TASK_ADMIN.DISABLE(...)

4. 對於maintenance windows,系統會切換到相應的resource plan。如果你不想你原來的resource plan 被切換掉的話,記得在你設置resource plan時,在resource plan的名字前面加上force:。如下面所示:

ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'FORCE:mydb_plan';

自動化是個好東西,不過這建立上你正確理解了它們的基礎上,要不有時就會出現莫名其妙的結果了。

舉個簡單的例子:如果你在某個時候truncate了一個表,之后重新加載了海量的數據,如果在你truncate后,加載數據之前,收集統計信息的任務啟動了,那么它會把這個表的統計信息更新為空表的數據。於是,你的很多涉及到這個表的SQL語句就會莫名其妙的慢下來甚至於執行不完了,原因就在於統計信息的錯誤變化(海量->空),導致CBO對很多語句從原來的索引訪問者變成了致命的全表掃描了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM