oracle10g logmnr的使用
一.安裝LogMiner
$ sqlplus /nolog
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Apr 15 12:30:58
Copyright (c) 1982, 2006, . All Rights Reserved.
SQL> conn / as sysdba;
Connected to an idle instance.
SQL> startup
ORACLE instance started.[@more@]一.安裝LogMiner
$ sqlplus /nolog
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Apr 15 12:30:58
Copyright (c) 1982, 2006, . All Rights Reserved.
SQL> conn / as sysdba;
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1392508928 bytes
Fixed Size 2072808 bytes
Variable Size 738201368 bytes
Database Buffers 637534208 bytes
Redo Buffers 14700544 bytes
Database mounted.
Database opened.
SQL>@?/rdbms/admin/dbmslm.sql
Package created.
Grant succeeded.
--dbmslm.sql是用來建立DBMS_LOGMNR的package,這個包是用來分析日誌的.
SQL>@?/rdbms/admin/dbmslmd.sql
Package created.
--dbmslmd.sql是用來建立DBMS_LOGMNR_D的package的,這個包是用來建立資料字典檔案的.
注意以上兩個包都是需要在sysdba許可權的user下建立.
二.使用LogMiner
安裝LogMiner確實很簡單,現在來看看如何使用我們安裝好的東東
1.首先需要建立資料字典檔案(data-dictionary):
為什麼要建立資料字典檔案呢?
引用一位網友的話就是:讓LogMiner引用涉及到內部資料字典中的部分時為他們實際的名字,而不是系統內部的16進位制。資料字典檔案是一個文字檔案,使用包 DBMS_LOGMNR_D來建立。如果我們要分析的中的表有變化,影響到庫的資料字典也發生變化,這時就需要重新建立該字典檔案。另外一種情況是在分析另外一個資料庫檔案的重作日誌時,也必須要重新生成一遍被分析資料庫的資料字典檔案。 在使用LogMiner工具分析redo log檔案之前,可以使用DBMS_LOGMNR_D 包將資料字典匯出為一個文字檔案。該字典檔案是可選的,但是如果沒有它,LogMiner解釋出來的語句中關於資料字典中的部分(如表名、列名等)和數值都將是16進位制的形式,我們是無法直接理解的。
在pfile或者spfile中,我們透過設定UTL_FILE_DIR引數來指定資料字典檔案的位置目錄
對於UTL_FILE_DIR引數在10g的文件中有這樣的解釋:
----------------------------------------------
UTL_FILE_DIR lets you specify one or more directories that Oracle should use for PL/SQL file I/O. If you are specifying multiple directories, you must repeat the UTL_FILE_DIR parameter for each directory on separate lines of the initialization parameter file.
All users can read or write to all files specified by this parameter. Therefore all PL/SQL users must be trusted with the information in the directories specified by this parameter.
Note:
If you list multiple values, all entries of this parameter must be on contiguous lines of the parameter file. If you separate them with other parameters, Oracle will read only the last (contiguous) lines.
開始設定UTL_FILE_DIR引數並建立資料字典檔案:
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /opt/oracle/product/10g/dbs/sp
fileirmdb.ora
SQL> alter system set UTL_FILE_DIR='/opt/oracle/product/10g/logmnr' scope=spfile;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1392508928 bytes
Fixed Size 2072808 bytes
Variable Size 738201368 bytes
Database Buffers 637534208 bytes
Redo Buffers 14700544 bytes
Database mounted.
Database opened.
SQL> show parameter UTL_FILE_DIR
NAME TYPE VALUE
------------------------------------ ----------- ----------------------------
utl_file_dir string /opt/oracle/product/10g/logmnr
現在開始建立資料字典:
SQL> show user;
USER is "SYS"
SQL>exec dbms_logmnr_d.build(dictionary_filename=>'alan_dict.ora',dictionary_location=>'/opt/oracle/product/10g/logmnr');
PL/SQL procedure successfully completed.
SQL> !
$ cd $ORACLE_HOME/logmnr
$ ls
alan_dict.ora
2.其次需要建立分析的日誌檔案列表:
首先看一下dbms_logmnr包的內容:
SQL> desc dbms_logmnr;
PROCEDURE ADD_LOGFILE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
LOGFILENAME VARCHAR2 IN
OPTIONS BINARY_INTEGER IN DEFAULT
FUNCTION COLUMN_PRESENT RETURNS BINARY_INTEGER
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_REDO_UNDO NUMBER IN DEFAULT
COLUMN_NAME VARCHAR2 IN DEFAULT
PROCEDURE END_LOGMNR
FUNCTION MINE_VALUE RETURNS VARCHAR2
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_REDO_UNDO NUMBER IN DEFAULT
COLUMN_NAME VARCHAR2 IN DEFAULT
PROCEDURE REMOVE_LOGFILE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
LOGFILENAME VARCHAR2 IN
PROCEDURE START_LOGMNR
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
STARTSCN NUMBER IN DEFAULT
ENDSCN NUMBER IN DEFAULT
STARTTIME DATE IN DEFAULT
ENDTIME DATE IN DEFAULT
DICTFILENAME VARCHAR2 IN DEFAULT
OPTIONS BINARY_INTEGER IN DEFAULT
SQL> select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 CURRENT
2 INACTIVE
3 INACTIVE
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/opt/oracle/oradata/irmdb/redo03.log
/opt/oracle/oradata/irmdb/redo02.log
/opt/oracle/oradata/irmdb/redo01.log
建立分析列表:
SQL>exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo01.log',Options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL>exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo02.log',Options=>dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
SQL>exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo03.log',Options=>dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
這樣不僅僅建立了日誌分析列表,同時還新增了兩個日誌成員檔案。
透過觀察v$logmnr_logs動態效能檢視我們可以看到分析列表中目前的日誌成員:
SQL>select filename from v$logmnr_logs;
FILENAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/irmdb/redo02.log
/opt/oracle/oradata/irmdb/redo03.log
/opt/oracle/oradata/irmdb/redo01.log
SQL> exec dbms_logmnr.remove_logfile('/opt/oracle/oradata/irmdb/redo02.log');
PL/SQL procedure successfully completed.
SQL> select filename from v$logmnr_logs;
FILENAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/irmdb/redo03.log
/opt/oracle/oradata/irmdb/redo01.log
SQL> exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo02.log',Options=>dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
3.利用LogMnr進行日誌挖掘和分析:
挖掘和分析分為兩種情況,一種是利用資料字典檔案對所有分析列表中的日誌內容進行分析,另外一種是利用資料字典檔案並帶有某種的限制條件對日誌內容進行分析,比如從某個時間點到某個時間點日誌內容的分析:
這裡列出一下dbms_logmnr.start_logmnr的結構:
PROCEDURE START_LOGMNR
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
STARTSCN NUMBER IN DEFAULT
ENDSCN NUMBER IN DEFAULT
STARTTIME DATE IN DEFAULT
ENDTIME DATE IN DEFAULT
DICTFILENAME VARCHAR2 IN DEFAULT
OPTIONS BINARY_INTEGER IN DEFAULT
對第一種情況進行分析:
-----------------------------------------
SQL>exec dbms_logmnr.start_logmnr(DictFileName=>'/opt/oracle/product/10g/logmnr/alan_dict.ora');
PL/SQL procedure successfully completed.
分析完畢後所有分析的內容都儲存到了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 GV$LOGMNR_CONTENTS t
where t.sql_redo like 'create%';
最後我們可以釋放記憶體:
SQL> exec dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
對第二種情況進行分析:
----------------------------------------
同時我們可以利用scn或time做為分析的限制條件,比如我們要分析日誌列表中時間從08.04.13從10:00到15:00的內容。
SQL>exec dbms_logmnr.start_logmnr
(startTime => to_date('20080413100000','yyyy-mm-dd hh24:mi:ss'),
endTime => to_date('20080413150000','yyyy-mm-dd hh24:mi:ss'),
DictFileName=>'/opt/oracle/product/10g/logmnr/alan_dict.ora');
PL/SQL procedure successfully completed
之後的操作就是查詢v$logmnr_contents或者gv$logmnr_contents檢視並進一步的分析
同時不要忘記最後釋放記憶體:
SQL>exec dbms_logmnr.end_logmnr;
$ sqlplus /nolog
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Apr 15 12:30:58
Copyright (c) 1982, 2006, . All Rights Reserved.
SQL> conn / as sysdba;
Connected to an idle instance.
SQL> startup
ORACLE instance started.[@more@]一.安裝LogMiner
$ sqlplus /nolog
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Apr 15 12:30:58
Copyright (c) 1982, 2006, . All Rights Reserved.
SQL> conn / as sysdba;
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1392508928 bytes
Fixed Size 2072808 bytes
Variable Size 738201368 bytes
Database Buffers 637534208 bytes
Redo Buffers 14700544 bytes
Database mounted.
Database opened.
SQL>@?/rdbms/admin/dbmslm.sql
Package created.
Grant succeeded.
--dbmslm.sql是用來建立DBMS_LOGMNR的package,這個包是用來分析日誌的.
SQL>@?/rdbms/admin/dbmslmd.sql
Package created.
--dbmslmd.sql是用來建立DBMS_LOGMNR_D的package的,這個包是用來建立資料字典檔案的.
注意以上兩個包都是需要在sysdba許可權的user下建立.
二.使用LogMiner
安裝LogMiner確實很簡單,現在來看看如何使用我們安裝好的東東
1.首先需要建立資料字典檔案(data-dictionary):
為什麼要建立資料字典檔案呢?
引用一位網友的話就是:讓LogMiner引用涉及到內部資料字典中的部分時為他們實際的名字,而不是系統內部的16進位制。資料字典檔案是一個文字檔案,使用包 DBMS_LOGMNR_D來建立。如果我們要分析的中的表有變化,影響到庫的資料字典也發生變化,這時就需要重新建立該字典檔案。另外一種情況是在分析另外一個資料庫檔案的重作日誌時,也必須要重新生成一遍被分析資料庫的資料字典檔案。 在使用LogMiner工具分析redo log檔案之前,可以使用DBMS_LOGMNR_D 包將資料字典匯出為一個文字檔案。該字典檔案是可選的,但是如果沒有它,LogMiner解釋出來的語句中關於資料字典中的部分(如表名、列名等)和數值都將是16進位制的形式,我們是無法直接理解的。
在pfile或者spfile中,我們透過設定UTL_FILE_DIR引數來指定資料字典檔案的位置目錄
對於UTL_FILE_DIR引數在10g的文件中有這樣的解釋:
----------------------------------------------
UTL_FILE_DIR lets you specify one or more directories that Oracle should use for PL/SQL file I/O. If you are specifying multiple directories, you must repeat the UTL_FILE_DIR parameter for each directory on separate lines of the initialization parameter file.
All users can read or write to all files specified by this parameter. Therefore all PL/SQL users must be trusted with the information in the directories specified by this parameter.
Note:
If you list multiple values, all entries of this parameter must be on contiguous lines of the parameter file. If you separate them with other parameters, Oracle will read only the last (contiguous) lines.
開始設定UTL_FILE_DIR引數並建立資料字典檔案:
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /opt/oracle/product/10g/dbs/sp
fileirmdb.ora
SQL> alter system set UTL_FILE_DIR='/opt/oracle/product/10g/logmnr' scope=spfile;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1392508928 bytes
Fixed Size 2072808 bytes
Variable Size 738201368 bytes
Database Buffers 637534208 bytes
Redo Buffers 14700544 bytes
Database mounted.
Database opened.
SQL> show parameter UTL_FILE_DIR
NAME TYPE VALUE
------------------------------------ ----------- ----------------------------
utl_file_dir string /opt/oracle/product/10g/logmnr
現在開始建立資料字典:
SQL> show user;
USER is "SYS"
SQL>exec dbms_logmnr_d.build(dictionary_filename=>'alan_dict.ora',dictionary_location=>'/opt/oracle/product/10g/logmnr');
PL/SQL procedure successfully completed.
SQL> !
$ cd $ORACLE_HOME/logmnr
$ ls
alan_dict.ora
2.其次需要建立分析的日誌檔案列表:
首先看一下dbms_logmnr包的內容:
SQL> desc dbms_logmnr;
PROCEDURE ADD_LOGFILE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
LOGFILENAME VARCHAR2 IN
OPTIONS BINARY_INTEGER IN DEFAULT
FUNCTION COLUMN_PRESENT RETURNS BINARY_INTEGER
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_REDO_UNDO NUMBER IN DEFAULT
COLUMN_NAME VARCHAR2 IN DEFAULT
PROCEDURE END_LOGMNR
FUNCTION MINE_VALUE RETURNS VARCHAR2
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_REDO_UNDO NUMBER IN DEFAULT
COLUMN_NAME VARCHAR2 IN DEFAULT
PROCEDURE REMOVE_LOGFILE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
LOGFILENAME VARCHAR2 IN
PROCEDURE START_LOGMNR
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
STARTSCN NUMBER IN DEFAULT
ENDSCN NUMBER IN DEFAULT
STARTTIME DATE IN DEFAULT
ENDTIME DATE IN DEFAULT
DICTFILENAME VARCHAR2 IN DEFAULT
OPTIONS BINARY_INTEGER IN DEFAULT
SQL> select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 CURRENT
2 INACTIVE
3 INACTIVE
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/opt/oracle/oradata/irmdb/redo03.log
/opt/oracle/oradata/irmdb/redo02.log
/opt/oracle/oradata/irmdb/redo01.log
建立分析列表:
SQL>exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo01.log',Options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SQL>exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo02.log',Options=>dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
SQL>exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo03.log',Options=>dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
這樣不僅僅建立了日誌分析列表,同時還新增了兩個日誌成員檔案。
透過觀察v$logmnr_logs動態效能檢視我們可以看到分析列表中目前的日誌成員:
SQL>select filename from v$logmnr_logs;
FILENAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/irmdb/redo02.log
/opt/oracle/oradata/irmdb/redo03.log
/opt/oracle/oradata/irmdb/redo01.log
SQL> exec dbms_logmnr.remove_logfile('/opt/oracle/oradata/irmdb/redo02.log');
PL/SQL procedure successfully completed.
SQL> select filename from v$logmnr_logs;
FILENAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/irmdb/redo03.log
/opt/oracle/oradata/irmdb/redo01.log
SQL> exec dbms_logmnr.add_logfile(LogFileName=>'/opt/oracle/oradata/irmdb/redo02.log',Options=>dbms_logmnr.ADDFILE);
PL/SQL procedure successfully completed.
3.利用LogMnr進行日誌挖掘和分析:
挖掘和分析分為兩種情況,一種是利用資料字典檔案對所有分析列表中的日誌內容進行分析,另外一種是利用資料字典檔案並帶有某種的限制條件對日誌內容進行分析,比如從某個時間點到某個時間點日誌內容的分析:
這裡列出一下dbms_logmnr.start_logmnr的結構:
PROCEDURE START_LOGMNR
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
STARTSCN NUMBER IN DEFAULT
ENDSCN NUMBER IN DEFAULT
STARTTIME DATE IN DEFAULT
ENDTIME DATE IN DEFAULT
DICTFILENAME VARCHAR2 IN DEFAULT
OPTIONS BINARY_INTEGER IN DEFAULT
對第一種情況進行分析:
-----------------------------------------
SQL>exec dbms_logmnr.start_logmnr(DictFileName=>'/opt/oracle/product/10g/logmnr/alan_dict.ora');
PL/SQL procedure successfully completed.
分析完畢後所有分析的內容都儲存到了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 GV$LOGMNR_CONTENTS t
where t.sql_redo like 'create%';
最後我們可以釋放記憶體:
SQL> exec dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
對第二種情況進行分析:
----------------------------------------
同時我們可以利用scn或time做為分析的限制條件,比如我們要分析日誌列表中時間從08.04.13從10:00到15:00的內容。
SQL>exec dbms_logmnr.start_logmnr
(startTime => to_date('20080413100000','yyyy-mm-dd hh24:mi:ss'),
endTime => to_date('20080413150000','yyyy-mm-dd hh24:mi:ss'),
DictFileName=>'/opt/oracle/product/10g/logmnr/alan_dict.ora');
PL/SQL procedure successfully completed
之後的操作就是查詢v$logmnr_contents或者gv$logmnr_contents檢視並進一步的分析
同時不要忘記最後釋放記憶體:
SQL>exec dbms_logmnr.end_logmnr;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7490392/viewspace-1018142/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Logmnr 工具的使用
- Oracle10G LOGMNR捕獲不到記錄Oracle
- Oracle logmnr使用Oracle
- Oracle10G LOGMNR捕獲不到記錄(二)Oracle
- Oracle10G LOGMNR捕獲不到記錄(一)Oracle
- LOGMNR的安裝和使用
- Oracle 10g Logmnr使用Oracle 10g
- 使用Logmnr恢復誤刪的資料
- LogMnr-誤DML後使用logmnr對資料進行恢復
- Oracle 使用logmnr檢視日誌Oracle
- oracle9i 中使用 logmnrOracle
- [Logmnr]使用logminer找回被誤刪的資料
- oracle logmnrOracle
- Oracle11g使用LOGMNR挖掘日誌Oracle
- 使用LOGMNR檢視資料庫日誌資料庫
- 日誌分析logmnr (Logminer) 使用方法
- oracle logmnr文件Oracle
- oracle 的dbms_logmnr用途Oracle
- 使用LOGMNR工具分析Oracle Redo Log和Archive Log教程Oracle RedoHive
- logmnr 日誌挖掘
- 一次失敗的logmnr操作
- ORACLE LOGMNR 日誌挖掘Oracle
- logmnr找出PACKAGE失效原因Package
- oracle 10g logmnrOracle 10g
- 使用logmnr分析歸檔日誌恢復被drop掉的資料表
- Oracle10g 使用注意點Oracle
- oracle10g oerr 命令使用Oracle
- 利用Logmnr找回誤刪除的資料
- Oracle logmnr簡單測試Oracle
- logmnr分析線上重做日誌
- ORACLE10G AWR使用和分析Oracle
- oracle10g建立使用者Oracle
- logmnr分析歸檔重做日誌
- oracle logmnr 報錯"In Memory Undo is unsupported"Oracle
- 使用dbms_logmnr.add_logfile增加線上重作日誌檔案
- oracle10g bbed編譯與使用Oracle編譯
- Oracle10g使用ASM注意事項OracleASM
- logmnr挖掘歸檔日誌檔案