Oracle 日誌挖掘(LogMiner)使用

 

 

Logminer依賴於2個包:DBMS_LOGMNR和DBMS_LOGMNR_D,Oracle 11g默認已安裝數據庫

 

Logminer 基本使用步驟session

<1>. Specify a LogMiner dictionary.   指定Logminer字典oracle

<2>. Specify a list of redo log files for analysis.   指定須要挖掘的redo或者archivelog日誌文件app

<3>. Start LogMiner.    開始日誌挖掘spa

<4>. Request the redo data of interest.    查詢V$LOGMNR_CONTENTS獲取挖掘的結果rest

<5>. End the LogMiner session.    結束日誌挖掘日誌

 

日誌挖掘使用示例:server

 

1.開啓補全日誌:htm


SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

ci


2.找出須要挖掘的歸檔日誌文件路徑

SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE FIRST_TIME between to_date('2018-07-06 08:20:00','yyyy-mm-dd hh24:mi:ss') and to_date('2018-07-06 09:40:00','yyyy-mm-dd hh24:mi:ss') order by 1;

NAME
--------------------------------------------------------------------------------
/u01/app/archive/1_342433_904747849.dbf
/u01/app/archive/1_342434_904747849.dbf
/u01/app/archive/1_342435_904747849.dbf


3.指定Logminer字典 (三選一)


Oracle 11g 指定Logminer字典有三種方法

1.Using the Online Catalog   使用在線目錄

2.Extracting a LogMiner Dictionary to the Redo Log Files   抽取字典到redo日誌文件中

3.Extracting the LogMiner Dictionary to a Flat File   抽取字典到平面文件中(須要設置UTL_FILE_DIR參數,重啓數據庫,不推薦

 

EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);

OR

EXECUTE DBMS_LOGMNR_D.BUILD( OPTIONS=> DBMS_LOGMNR_D.STORE_IN_REDO_LOGS);

OR

EXECUTE DBMS_LOGMNR_D.BUILD('dictionary.ora', '/oracle/database/', DBMS_LOGMNR_D.STORE_IN_FLAT_FILE);


4.Logminer中添加歸檔日誌文件

EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '/u01/app/archive/1_342433_904747849.dbf', OPTIONS => DBMS_LOGMNR.NEW);

繼續添加日誌:
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '/u01/app/archive/1_342434_904747849.dbf', OPTIONS => DBMS_LOGMNR.ADDFILE);

EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '/u01/app/archive/1_342435_904747849.dbf', OPTIONS => DBMS_LOGMNR.ADDFILE);

查看添加的日誌列表:
select filename from V$LOGMNR_LOGS;


5.開始日誌挖掘 (三選一,與步驟3對應)

EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
OR
EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_REDO_LOGS );
OR
EXECUTE DBMS_LOGMNR.START_LOGMNR(DICTFILENAME =>'/oracle/database/dictionary.ora');


6.獲取挖掘結果

SELECT username AS USR, (XIDUSN || '.' || XIDSLT || '.' || XIDSQN) AS XID,
SQL_REDO, SQL_UNDO FROM V$LOGMNR_CONTENTS WHERE username IN ('HR', 'OE');

把挖取結果保存到指定表格中: create table logtab as select * from v$logmnr_contents;


7.結束日誌挖掘

EXECUTE DBMS_LOGMNR.END_LOGMNR;

 

更多詳細介紹,參考官方文檔:https://docs.oracle.com/cd/E11882_01/server.112/e22490/logminer.htm#SUTIL1557

相關文章
相關標籤/搜索