一.Logminer分类
从官方提供的图可知,logminer 基本可分为两类,三种:
1)使用 online catalog 作为记录数据字典信息的方式进行数据抽取(源库自身的数据字典);
2)使用外部数据库已创建过redo log文件中记录数据字典信息的方式进行数据挖掘(外部库的数据字典);
3)使用外部文件作为数据字典的方式,在其他库中进行数据挖掘(利用外部库的字典文件,需要创建UTL_FILE_DIR);
二.安装Logminer
使用LOGMINER需要下面2个sql:
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
6. End the LogMiner Session
3.1)Database-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.3)Specify Redo Log Files for Analysis(Local)
【参考自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.4)Start LogMiner
执行DBMS_LOGMNR.START_LOGMNR Function
exec sys.dbms_logmnr.start_logmnr( options => sys.dbms_logmnr.dict_from_online_catalog ); |
3.5)Query 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: