Logminer 之 Using the dictionary in the online catalog

 一.Logminer分類

從官方提供的圖可知,logminer 基本可分爲兩類,三種:

1)使用 online catalog 作爲記錄數據字典信息的方式進行數據抽取(源庫自身的數據字典);

2)使用外部數據庫已創建過redo log文件中記錄數據字典信息的方式進行數據挖掘(外部庫的數據字典);

3)使用外部文件作爲數據字典的方式,在其他庫中進行數據挖掘(利用外部庫的字典文件,需要創建UTL_FILE_DIR);

 

二.安裝Logminer

使用LOGMINER需要下面2sql

Dbmslm.sql

Dbmslmd.sql

 

三.在源數據庫庫中,使用online catalog方式記錄數據庫對象真實名稱的信息,步驟如:

1. Enable Supplemental Logging

2. Extract a LogMiner Dictionary (unless you plan to use the online catalog)

3. Specify Redo Log Files for Analysis

4. Start LogMiner

5. Query V$LOGMNR_CONTENTS

6End the LogMiner Session

 

3.1Database-Level or table-level Supplemental Logging

Enable supplemental logging:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

 

啓用其他補充日誌:

supplemental logging:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;


禁用:

ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;

ALTER DATABASE DROP SUPPLEMENTAL LOG DATA;

 

第一種方式不需要指定數據字典

 

3.3Specify Redo Log Files for AnalysisLocal 

【參考自Tom kytes】

column member new_val M

select a.member, b.status from v$logfile a, v$log b where a.group# = b.group# and b.status = 'CURRENT';

exec sys.dbms_logmnr.add_logfile( 'C:\ORACLE\APP\WONDERFUL\ORADATA\ORCL\REDO02.LOG' );

 


如果需要,可用add_logfile 添加其他需要被抽取的redo(或歸檔日誌)日誌

EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -

LOGFILENAME => 'xxxx1.log', -

OPTIONS => DBMS_LOGMNR.ADDFILE);

Or

EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -

LOGFILENAME=>'xxx2.log');



如果不需要則可以使用remove_logfile 益處:

EXECUTE DBMS_LOGMNR.REMOVE_LOGFILE( -

LOGFILENAME => 'xxxx2.log');



【補充】

如果使用第二種或者第三中外部數據庫的方式,當指定redo已經歸檔,則使用歸檔,

可使用下面方法確定哪些歸檔有記錄過數據字典信息:

SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN='YES';

SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_END='YES';

 

3.3.1 測試數據

conn / as sysdba

Grant dba to hr;

Conn hr/hr

Update  jobs set max_salary=100000 where min_sqlary>10000;

Commit;


 

 

3.4Start LogMiner

執行DBMS_LOGMNR.START_LOGMNR Function

exec sys.dbms_logmnr.start_logmnr( options => sys.dbms_logmnr.dict_from_online_catalog );



3.5Query V$LOGMNR_CONTENTS

SQL> col sql_redo for a60

SQL> col sql_undo for a60

SQL> col xid for a20

SQL> col usr for a20

SQL> set linesize 180

SQL>SELECT username AS USR, (XIDUSN || '.' || XIDSLT || '.' ||  XIDSQN) AS XID, SQL_REDO, SQL_UNDO 

FROM V$LOGMNR_CONTENTS WHERE username IN ('HR', 'OE');

 

 

 

3.6)結束當前logminer

exec sys.dbms_logmnr.end_logmnr;


補充:

1.you can find out which redo log files contain the start and end ofan extracted dictionary. To do so, query the V$ARCHIVED_LOG view, 

as follows:

可以根據下面查詢發現記錄數據對象真實名稱的數據字典存放在哪個redo logfile或歸檔日誌

SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN='YES';

SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_END='YES';

 

 

2.To determine which redo log files are being analyzed in the current LogMinersession, you can query the V$LOGMNR_LOGS view, 

which contains one row foreach redo log file.After a successful call to DBMS_LOGMNR.START_LOGMNR, the STATUS column of the

V$LOGMNR_LOGS view contains one of the following values:

 0 Indicates that the redo log file will be processed during a query of the V$LOGMNR_

CONTENTS view.

表示此類日誌文件信息會被記錄進入v$logmnr_contents視圖

■ 1 Indicates that this will be the first redo log file to be processed by LogMiner

during a select operation against the V$LOGMNR_CONTENTS view.

表示這類日誌只是其中需要抽取的一部分,還需要其他日誌添加才能讀取完整的數據。

■ 2 Indicates that the redo log file has been pruned and therefore will not be processed

by LogMiner during a query of the V$LOGMNR_CONTENTS view. It has been

pruned because it is not needed to satisfy your requested time or SCN range.

■ 4 Indicates that a redo log file

Example

 

 


發佈了87 篇原創文章 · 獲贊 10 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章