1. 程式人生 > >自動撤銷管理(AUM)

自動撤銷管理(AUM)

一設定AUM

  設定自動撤銷管理,涉及三個引數:undo_management、undo_tablespace、undo_retention

  1、undo_management

  設定自動撤銷管理,必須設定初始化引數undo_management=auto

  alter system set undo_management=auto scope=spfile;

  該引數也是必須要設定的

  2、undo_tablespace

  指定資料庫使用的撤銷表空間

  (1)如果沒有指定該引數且沒有可用的撤銷表空間,oracle將使用system表空間。

  如果沒有指定該引數,但有撤銷表空間,oracle將使用該撤銷表空間;若有多個撤銷表空間,oracle將使用第一個可用的作為資料庫撤銷表空間。

  如果該引數指定的撤銷表空間不存在,將報錯。

  (2)即便資料庫中有多個撤銷表空間,oracle在同一時間也將只是用一個;可以使用該引數切換oracle使用的撤銷表空間

  alter system set undo_tablespace=undo_tablespace_name;

  oracle使用的撤銷表空間不能被刪除,需要刪除的話,必須先切換撤銷表空間。

  (3)建立撤銷表空間:

  create undo tablespace undo_tablespace_name

  datafile 'data_path_name'

  size nm

  [autoextend on next mm maxsize pm]

  [extent management local ]                            

  [segment space management manual]  --撤銷表空間的段空間管理必須為manual

  [{uniform [ size am] } | autoallocate]

  (4)如果不能確定撤銷表空間的大小,可以先使用自動擴充套件的資料檔案,在建立撤銷表空間時指定,也可以通過下面方式:

  alter database datafile 'datafile_path_name' autoextend on next mm maxszie pm;

  在確定撤銷表空間的大小後再使用固定的表空間:

  alter database datafile 'datafile_path_name' autoextnd off;

  3、undo_retention

  指定已提交事務的撤銷資料保留的時間長短

  alter system set undo_retention=n            --n為保留的時間大小,預設為900,單位秒

  oracle絕對保證活動的撤銷資料,即事務尚未提交的撤銷資料。如果空間不足,將先刪除事務已經提交且保留時間超過undo_retention設定值的撤銷資料,如果空間仍然不足,將刪除事務已經提交但保留時間未超過undo_retention設定值的撤銷資料。

  (1)使用AUM且資料檔案自動擴充套件,oracle將以undo_retention設定的值為最小值,自動調整撤銷保留時間,照顧到資料庫中最長查詢的撤銷要求。

  (2)使用AUM但固定資料檔案,oracle將忽略使用者設定的undo_retention的值,自動調整撤銷保留時間,盡最大努力保留撤銷資料。

  (3)前兩種情況相比,如果空間允許,一般使用固定資料檔案時撤銷資料保留的時間要長。

二、如何設定undo_retention?

  建議參考資料庫中最長事務的時間大小,設定的undo_retention應該比最長事務的時間稍大一點。

  select max(maxquerylen) from v$undostat;

  如果使用閃回,應該保證undo_retention的設定能夠滿足的閃回要求。

三、如何確定撤銷表空間的大小

  建議首先建立自動擴充套件的撤銷表空間,之後使用undo advisor確定撤銷表空間的大小,然後更改撤銷表空間為固定大小。

四、有保證的撤銷保留

  使用undo_retention設定保留時間,oracle並不一定能滿足你的要求,當空間不足時,oracle依然會刪除沒有達到保留時間的撤銷資料。如果需要強制oracle按照你設定值保留撤銷資料,可以使用有保證的撤銷保留。

  1、create undo tablespace

       .....

       retention guarantee;

  2、alter tablespace undo_tablespace_name retention guarantee;

  取消有保證的撤銷保留:alter tablespace undo_tablespace_name retention noguarantee;

  使用有保證的撤銷保留,如果空間不足以滿足活動事務,那麼所有的DML操作都不允許,會收到空間出超的錯誤;二DDL語句可以繼續進行。