日誌分析logmnr使用方法
阿新 • • 發佈:2019-01-27
一、安裝LogMiner工具,以下兩個指令碼以SYSDBA身份執行
@$Oracle_HOME/rdbms/admin/dbmslm.sql;
@ $ORACLE_HOME/rdbms/admin/dbmslmd.sql;
第一個指令碼用來建立DBMS_LOGMNR包,該包用來分析日誌檔案。
第二個指令碼用來建立DBMS_LOGMNR_D包,該包用來建立資料字典檔案。
二、使用LogMiner工具
下面將具體介紹如何使用LogMiner工具。
1、建立資料字典檔案(data-dictionary)
1).首先在init.ora初始化引數檔案中,指定資料字典檔案的位置,也就是新增一個引數UTL_FILE_DIR,該引數值為伺服器中放置資料字典檔案的目錄。如:UTL_FILE_DIR = ($ORACLE_HOME/logs) ,重新啟動資料庫
2).然後建立資料字典檔案
SQL> connect /as sysdba
SQL> execute dbms_logmnr_d.build(dictionary_filename => 'dict.ora',dictionary_location => 'G:/oracle/logs');
PL/SQL procedure sUCcessfully completed
2、建立要分析的日誌檔案列表
1).建立分析列表,即所要分析的日誌
SQL> execute dbms_logmnr.add_logfile(LogFileName => 'G:/ORACLE/ORADATA/ORADBSP/REDO04.LOG',Options => dbms_logmnr.new);
PL/SQL procedure successfully completeds
2).新增分析日誌檔案,一次新增1個為宜
SQL> execute dbms_logmnr.add_logfile(LogFileName => 'G:/ORACLE/ORADATA/ORADBSP/REDO05.LOG',Options => dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed
3、使用logMiner進行日誌分析
1).無限制條件,即用資料字典檔案對要分析的日誌檔案所有內容做分析
SQL> execute dbms_logmnr.start_logmnr(DictFileName => 'G:/oracle/logs/dict.ora');
PL/SQL procedure successfully completed
2).帶限制條件,可以用scn號或時間做限制條件,也可組合使用
--分析日誌列表中時間從07.02.28從10:00到15:00的內容
SQL> execute dbms_logmnr.start_logmnr(startTime => to_date('20070228100000','yyyy-mm-dd hh24:mi:ss'),endTime => to_date('20070228150000','yyyy-mm-dd hh24:mi:ss'),DictFileName => 'G:/oracle/logs/dict.ora');
PL/SQL procedure successfully completed
dbms_logmnr.start_logmnr函式的原型為:
PROCEDURE start_logmnr(
startScn IN NUMBER default 0 ,
endScn IN NUMBER default 0,
startTime IN DATE default '',
endTime IN DATE default '',
DictFileName IN VARCHAR2 default '',
Options IN BINARY_INTEGER default 0 );
4.分析後釋放記憶體
SQL> execute dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed
5.其它
1).刪除日誌分析檔案
exec dbms_logmnr.add_logfile('G:/ORACLE/ORADATA/ORADBSP/REDO04.LOG',dbms_logmnr.removefile);
三、檢視LogMiner工具分析結果
SQL> select * from dict t where t.table_name like '%LOGMNR%';--看所有與logmnr相關的檢視
TABLE_NAME COMMENTS
------------------------------ --------------------------------------------------------------------------------
GV$LOGMNR_CALLBACK Synonym for GV_$LOGMNR_CALLBACK
GV$LOGMNR_CONTENTS Synonym for GV_$LOGMNR_CONTENTS
GV$LOGMNR_DICTIONARY Synonym for GV_$LOGMNR_DICTIONARY
GV$LOGMNR_LOGFILE Synonym for GV_$LOGMNR_LOGFILE
GV$LOGMNR_LOGS Synonym for GV_$LOGMNR_LOGS
GV$LOGMNR_PARAMETERS Synonym for GV_$LOGMNR_PARAMETERS
GV$LOGMNR_PROCESS Synonym for GV_$LOGMNR_PROCESS
GV$LOGMNR_REGION Synonym for GV_$LOGMNR_REGION
GV$LOGMNR_SESSION Synonym for GV_$LOGMNR_SESSION
GV$LOGMNR_STATS Synonym for GV_$LOGMNR_STATS
GV$LOGMNR_TRANSACTION Synonym for GV_$LOGMNR_TRANSACTION
V$LOGMNR_CALLBACK Synonym for V_$LOGMNR_CALLBACK
V$LOGMNR_CONTENTS Synonym for V_$LOGMNR_CONTENTS
V$LOGMNR_DICTIONARY Synonym for V_$LOGMNR_DICTIONARY
V$LOGMNR_LOGFILE Synonym for V_$LOGMNR_LOGFILE
V$LOGMNR_LOGS Synonym for V_$LOGMNR_LOGS
V$LOGMNR_PARAMETERS Synonym for V_$LOGMNR_PARAMETERS
V$LOGMNR_PROCESS Synonym for V_$LOGMNR_PROCESS
V$LOGMNR_REGION Synonym for V_$LOGMNR_REGION
V$LOGMNR_SESSION Synonym for V_$LOGMNR_SESSION
TABLE_NAME COMMENTS
------------------------------ --------------------------------------------------------------------------------
V$LOGMNR_STATS Synonym for V_$LOGMNR_STATS
V$LOGMNR_TRANSACTION Synonym for V_$LOGMNR_TRANSACTION
GV$LOGMNR_LOGS 是分析日誌列表檢視
分析結果在GV$LOGMNR_CONTENTS 檢視中,可按以下語句查詢:
select scn,timestamp,log_id,seg_owner,seg_type,table_space,data_blk#,data_obj#,data_objd#,
session#,serial#,username,session_info,sql_redo,sql_undo
from logmnr3 t
where t.sql_redo like 'create%';
假如不能正常查詢GV$LOGMNR_CONTENTS檢視,並報以下錯誤,ORA-01306: 在從 v$logmnr_contents 中選擇之前必須呼叫 dbms_logmnr.start_logmnr() 。可採用如下方法:
create table logmnr3 as select * from GV$LOGMNR_CONTENTS;
FAQ:
1.建立資料字典的目 : 讓LogMiner引用涉及到內部資料字典中的部分時為他們實際的名字,而不是系統內部的16進位制。資料字典檔案是一個文字檔案,使用包DBMS_LOGMNR_D來建立。假如我們要分析的資料庫中的表有變化,影響到庫的資料字典也發生變化,這時就需要重新建立該字典檔案。另外一種情況是在分析另外一個數據庫檔案
INSERT INTO dm_dj_swry (rydm, rymc) VALUES (00005, '張三');
LogMiner解釋出來的結果將是下面這個樣子,
insert into Object#308(col#1, col#2) values (hextoraw('c30rte567e436'), hextoraw('4a6f686e20446f65'));