CREATE TABLESPACE TBS_LOGMNR DATAFILE ' /oracle/app/oracle/oradata/testdb/TBS_LOGMNR01.dbf' SIZE 2570M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON; CREATE USER LOGMNR IDENTIFIED BY xxxx DEFAULT TABLESPACE TBS_LOGMNR TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK; -- 2 Roles for LOGMNR GRANT CONNECT TO LOGMNR; GRANT RESOURCE TO LOGMNR; ALTER USER LOGMNR DEFAULT ROLE ALL; -- 1 System Privilege for LOGMNR GRANT UNLIMITED TABLESPACE TO LOGMNR;2.搜尋現有ARCHIVED LOG,資料字典(DICT)所在位置。
SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN='YES';
資料字典可讓LOGMNR將交易SQL對應到正確之資料庫物件,關係後續進行資料倒回時物件之正確性。所找尋之DICT應以接近異常事件時間點之檔案為佳。以下假設所搜尋到之檔案為
1_15141_708784153.dbf。
select * from v$log;
將現有REDO LOG檔案加入LOGMNR
3.將LOGMNR工具的TABLESPACE移至新建的空間位置。(CONSOLE)
EXECUTE dbms_logmnr_d.set_tablespace('TBS_LOGMNR');
4.修改資料庫:新增額外LOG紀錄。(CONSOLE)
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
5.LOGMNR操作:(CONSOLE)
建立LOGMNR
EXECUTE DBMS_LOGMNR_D.BUILD( OPTIONS=> DBMS_LOGMNR_D.STORE_IN_REDO_LOGS);
加入欲分析之LOGFILE(若有未加入之字典,會顯示字典不完全)
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '/ora00/oracle/oradata/testdb/redo03.log',OPTIONS => DBMS_LOGMNR.NEW);
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '/ora00/oracle/product/102/dbs/arch/1_15141_708784153.dbf',OPTIONS => DBMS_LOGMNR.ADDFILE);
移除不用的LOGFILE(視需求)
EXECUTE DBMS_LOGMNR.REMOVE_LOGFILE(LOGFILENAME =>'/ora00/oracle/product/102/dbs/arch/1_14980_708784153.dbf.dbf');
開始進行分析
EXECUTE dbms_logmnr.start_logmnr(options => DBMS_LOGMNR.DICT_FROM_REDO_LOGS);
匯出分析結果(由v$logmnr_contents表格匯出,可使用SQL過濾條件,表格欄位如下)。以下範例搜尋對HOSEN, WILMAR及CGBT作刪除之SQL,並將其匯出至LOGMNR的表格LOGMNR_14986
create table LOGMNR.logmnr_14986 tablespace TBS_LOGMNR as select * from v$logmnr_contents where RBASQN=14986 and operation='DELETE' and seg_owner='HCOMPANY' or seg_owner='WCOMPANY' or seg_owner='CCOMPANY';
6.運用LOGMNR進行復原操作:上述用LOGMNR所搜尋之SQL紀錄,有兩個欄位作為異常交易倒回之依據:SQL_REDO與SQL_UNDO。
SQL_REDO:異常交易之SQL指令(已被執行的SQL)(在此假設執行INSERT指令)
結論。
異常復原最花時間是能正確鎖定問題時間點,找到正確的Archived Logfile和資料字典,若未能找到正確的Logfile或無正確字典,則無法進行。