Oracle LOGMNR
作者:互联网
--1、创建数据字典存入目录
mkdir /home/oracle/logmnr
--2、安装logminer功能
@?/rdbms/admin/dbmslm.sql
@?/rdbms/admin/dbmslmd.sql
@?/rdbms/admin/dbmslms.sql
--3、数据库中修改目录
--查看utl_file_dir参数
show parameter utl_file_dir
--修改
alter system set utl_file_dir='/home/oracle/logmnr' scope=spfile;
--4、创建数据字典
execute dbms_logmnr_d.build(dictionary_filename => 'dict20170123.dat',dictionary_location => '/home/oracle/logmnr');
--5、添加在线日志文件
execute dbms_logmnr.add_logfile(options=>dbms_logmnr.new,logfilename=>'/oracle/oradata/gsdb/redo01.log');
execute dbms_logmnr.add_logfile(options=>dbms_logmnr.new,logfilename=>'/oracle/oradata/gsdb/redo02.log');
execute dbms_logmnr.add_logfile(options=>dbms_logmnr.new,logfilename=>'/oracle/oradata/gsdb/redo03.log');
--或添加归档
execute dbms_logmnr.add_logfile(options=>dbms_logmnr.new,logfilename=>'/archivelog/1_195_897305159.dbf');
--删除日志dbms_logmnr.removefile 删除后需要重新启动logmnr,否则也会报ora 01306错误。
execute dbms_logmnr.add_logfile(options=>dbms_logmnr.removefile,logfilename=>'/oracle/oradata/gsdb/redo03.log');
execute dbms_logmnr.remove_logfile(logfilename=>'/oracle/oradata/gsdb/redo02.log');
--6、启用日志分析
--开启日志挖掘
exec dbms_logmnr.start_logmnr(dictfilename=>'/u01/dblog/dict.ora');
--使用在线数据字典:
EXEC DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
--无条件限制
execute dbms_logmnr.start_logmnr(DictFileName=>'/home/oracle/logmnr/dict20170123.dat');
--指定特定时间段
execute dbms_logmnr.start_logmnr(dictfilename =>'/home/oracle/logmnr/dict20170122.dat',starttime => to_date('2017-01-22 13:00:00','YYYY-MM-DD HH24:MI:SS'),endtime => to_date('2017-01-22 13:10:00','YYYY-MM-DD HH24:MI:SS'));
execute dbms_logmnr.start_logmnr(dictfilename =>'/home/oracle/logmnr/dict20170123.dat',starttime => to_date('2017-01-22 13:47:00','YYYY-MM-DD HH24:MI:SS'),endtime => to_date('2017-01-22 13:47:29','YYYY-MM-DD HH24:MI:SS'));
--7、查看分析结果
--(分析结果只存在于执行start_logmnr这个会话,logminer存储在PGA中,其它进程看不到,如果其它会话查看分析结果,会报ora-01306)
select * from v$logmnr_contents;
select sql_redo from v$logmnr_contents;
select timestamp,username,session#,sql_redo,operation from v$logmnr_contents where sql_redo like 'delete%';
--保存分析结果:
create table log_1 as select * from v$logmnr_contents;
--8、结束分析
--(进程结束,分析结果也随之消失,PGA内存区域清空)
--(选作)
create table log_redo as select * from v$logmnr_contents;
--关闭
exec dbms_logmnr.end_logmnr;
--9、如果要分析其它库日志,先获取其它库dbid (select dbid from v$database),vi 当前数据字典,替换掉当前的dbid值。否则报ora-01295
--10、如果要分析sqlload语句
--首先不能使用direct=true
--其次开户补全日志
--查询
select SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_UI,FORCE_LOGGING from v$database;
--结果
SUPPLEME SUP SUP FOR
-------- --- --- ---
NO NO NO NO
--开启
alter database add supplemental log data;
--查询
select SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_UI,FORCE_LOGGING from v$database;
--结果
SUPPLEME SUP SUP FOR
-------- --- --- ---
YES NO NO NO
--经测试可以直接修改,不用重启数据库。
--官方操作步骤为
shutdown immediate
startup mount
SQL> alter database add supplemental log data;
alter database open;
SQL> select SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_UI,FORCE_LOGGING from v$database;
SUPPLEME SUP SUP FOR
-------- --- --- ---
YES NO NO NO
标签:dbms,NO,execute,LOGMNR,oracle,logmnr,Oracle,SUPPLEMENTAL 来源: https://blog.csdn.net/HKING_H/article/details/89739798