1. 程式人生 > >Oracle 日誌挖掘logminer

Oracle 日誌挖掘logminer

用途

  • 對oracle線上redo,歸檔日誌進行分析。

目的

  • 修正誤操作
  • 審計

dbms_logmnr

  • 可以基於日誌檔案分析(一個或者多個)
  • 可以基於時間段分析
  • 可以基於SCN分析

例項

往t表插入數字1至9

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 
Connected as test@local

SQL> select * from v$logfile;
    GROUP# STATUS  TYPE    MEMBER                                                                           IS_RECOVERY_DEST_FILE
--
-------- ------- ------- -------------------------------------------------------------------------------- --------------------- 3 ONLINE E:\ORACLE\ORADATA\ORCL\REDO03.LOG NO 2 ONLINE E:\ORACLE\ORADATA\ORCL\REDO02.LOG NO 1
ONLINE E:\ORACLE\ORADATA\ORCL\REDO01.LOG NO SQL> select * from v$log; GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME ---------- ---------- --------
-- ---------- ---------- ---------- -------- ---------------- ------------- ----------- ------------ ----------- 1 1 10 52428800 512 1 NO INACTIVE 1089257 2018/12/17 1097614 2018/12/17 2 1 11 52428800 512 1 NO CURRENT 1097614 2018/12/17 281474976710 3 1 9 52428800 512 1 NO INACTIVE 1058362 2018/12/2 1 1089257 2018/12/17 SQL> select dbms_flashback.get_system_change_number from dual; GET_SYSTEM_CHANGE_NUMBER ------------------------ 1098917 SQL> insert into t select rownum from dual connect by rownum<10; 9 rows inserted SQL> commit; Commit complete SQL> select dbms_flashback.get_system_change_number from dual; GET_SYSTEM_CHANGE_NUMBER ------------------------ 1098933 SQL> exec dbms_logmnr.add_logfile('E:\ORACLE\ORADATA\ORCL\REDO02.LOG',dbms_logmnr.new); PL/SQL procedure successfully completed SQL> exec dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog,StartScn=>1098917,EndScn=>1098933); PL/SQL procedure successfully completed SQL> select operation,sql_redo,sql_undo from v$logmnr_contents; OPERATION SQL_REDO SQL_UNDO -------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- START set transaction read write; INSERT insert into "TEST"."T"("NO") values ('1'); delete from "TEST"."T" where "NO" = '1' and ROWID = 'AAAR7VAAFAAAACGAAA'; INSERT insert into "TEST"."T"("NO") values ('2'); delete from "TEST"."T" where "NO" = '2' and ROWID = 'AAAR7VAAFAAAACGAAB'; INSERT insert into "TEST"."T"("NO") values ('3'); delete from "TEST"."T" where "NO" = '3' and ROWID = 'AAAR7VAAFAAAACGAAC'; INSERT insert into "TEST"."T"("NO") values ('4'); delete from "TEST"."T" where "NO" = '4' and ROWID = 'AAAR7VAAFAAAACGAAD'; INSERT insert into "TEST"."T"("NO") values ('5'); delete from "TEST"."T" where "NO" = '5' and ROWID = 'AAAR7VAAFAAAACGAAE'; INSERT insert into "TEST"."T"("NO") values ('6'); delete from "TEST"."T" where "NO" = '6' and ROWID = 'AAAR7VAAFAAAACGAAF'; INSERT insert into "TEST"."T"("NO") values ('7'); delete from "TEST"."T" where "NO" = '7' and ROWID = 'AAAR7VAAFAAAACGAAG'; INSERT insert into "TEST"."T"("NO") values ('8'); delete from "TEST"."T" where "NO" = '8' and ROWID = 'AAAR7VAAFAAAACGAAH'; INSERT insert into "TEST"."T"("NO") values ('9'); delete from "TEST"."T" where "NO" = '9' and ROWID = 'AAAR7VAAFAAAACGAAI'; COMMIT commit; 11 rows selected

實驗中遇到的錯誤

  • 啟用補充日誌
    不啟用不影響整個過程,但最終查詢時部分操作(像插入,刪除,會報"Unsupported"錯誤)分析不出來
    啟用補充日誌命令:alter database add supplemental log data;
    刪除補充日誌命令:alter database drop supplemental log data;