执行脚本安装logminer
[oracle@fogtestdb admin]$ sqlplus / as sysdba
SQL> @$ORACLE_HOME/rdbms/admin/dbmslm.sql
Package created.
Grant succeeded.
Synonym created.
SQL> @$ORACLE_HOME/rdbms/admin/dbmslmd.sql
Package created.
Synonym created.
创建数据字典文件
SQL> show parameter utl_file_dir
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string
SQL> alter system set utl_file_dir = '/u01/app/logminer' scope = spfile;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1503199232 bytes
Fixed Size 2228544 bytes
Variable Size 1140854464 bytes
Database Buffers 352321536 bytes
Redo Buffers 7794688 bytes
Database mounted.
Database opened.
SQL> show parameter utl_file_dir
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string /u01/app/logminer
SQL> exec dbms_logmnr_d.build( 'dictionary.ora', '/u01/app/logminer');
PL/SQL procedure successfully completed.
开启补充日志
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
添加日志(redo or arch)
SQL> exec dbms_logmnr.add_logfile('/u01/app/oracle/oradata/mytest/redo01.log');
PL/SQL procedure successfully completed.
分析日志
SQL> exec dbms_logmnr.start_logmnr( dictfilename=>'/u01/app/logminer/dictionary.ora');
PL/SQL procedure successfully completed.
查看结果
select operation,sql_redo,sql_undo from v$logmnr_contents;
结束分析
exec dbms_logmnr.end_logmnr;
其他
V$LOGMNR_DICTIONARY-------查询使用的数据字典文件
V$LOGMNR_PARAMETERS-------查询当前LogMiner设定的参数
指定时间的分析
EXECUTE dbms_logmnr.start_logmnr(
DictFileName => dictfilename=>'D:\..\practice\LOGMNR\dictionary.ora',
StartTime =>to_date('2013-6-8 00:00:00','YYYY-MM-DD HH24:MI:SS')
EndTime =>to_date(''2013-6-8 23:59:59','YYYY-MM-DD HH24:MI:SS '));
SCN和日期转换
select scn_to_timestamp(8908390522972) scn from dual;
select timestamp_to_scn(sysdate) scn from dual;
异机logminer
如果生产库设置了utl_file_dir参数,直接把生成的dictionary.ora数据字典文件复制到其他库,再其他库上进行分析,指定使用生产库的数据字典文件即可。
如果生产库未设置utl_file_dir参数,生产库不能重启,无法抽取出生产库的数据字典
操作步骤:
生产库:
抽取数据字典到redo log
EXECUTE DBMS_LOGMNR_D.BUILD( OPTIONS=> DBMS_LOGMNR_D.STORE_IN_REDO_LOGS);
记录数据字典所在的日志文件
SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN='YES';
--开始的日志文件
SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_END='YES';
--结束的日志文件
测试库:
logminer加载日志:
EXECUTE DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME => '第一个文件', OPTIONS => DBMS_LOGMNR.NEW);
--数据字典日志文件
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '之后的文件', OPTIONS => DBMS_LOGMNR.ADDFILE);
--数据字典日志文件,加载开始到结束的全部日志文件
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( LOGFILENAME => '需要挖掘的日志文件', OPTIONS => DBMS_LOGMNR.ADDFILE);
--添加需要挖掘的
开始数据挖掘:
EXECUTE DBMS_LOGMNR.START_LOGMNR( OPTIONS =>DBMS_LOGMNR.COMMITTED_DATA_ONLY+dbms_logmnr.NO_ROWID_IN_STMT+dbms_logmnr.DICT_FROM_REDO_LOGS); --使用dbms_logmnr.DICT_FROM_REDO_LOGS
5、挖掘查询结果:
SELECT scn,seg_owner,operation,timestamp,status,sql_redo,seg_name FROM v$logmnr_contents
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29320885/viewspace-2135827/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29320885/viewspace-2135827/