登陆到CDB(下面的执行都需要在cdb root模式下执行)
以下的语句都需要在同一个会话内执行
数据库需要开启补充日志
alter database add supplemental log data;
select supplemental_log_data_min from v$database;
在默认情况下,Oracle已经安装了LogMiner工具。若是没有安装,则可以运行下面两个脚本:
SQL>@$ORACLE_HOME/rdbms/admin/dbmslm.sql
SQL>@$ORACLE_HOME/rdbms/admin/dbmslmd.sql
1.添加需要分析的归档日志
begin
dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/archlog/1_1206_1032346838.dbf',options=>dbms_logmnr.new);
end;
begin
dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/archlog/1_1207_1032346838.dbf',options=>dbms_logmnr.addfile);
end;
begin
dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/archlog/1_1208_1032346838.dbf',options=>dbms_logmnr.addfile);
end;
如需移除日志使用
execute dbms_logmnr.remove_logfile(logfilename=>'/u01/app/oracle/archlog/1_1208_1032346838.dbf');
2.查看当前添加分析的归档日志文件
select * from v$logmnr_logs;
3.开始分析
begin
dbms_logmnr.start_logmnr(Options => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
end;
启动分析时还可以指定时间或者scn
begin
dbms_logmnr.start_logmnr(Options => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG,starttime => to_date('2020-07-03 09:30:00','YYYY-MM-DD HH24:MI:SS'),endtime => to_date('2020-07-03 10:30:00','YYYY-MM-DD HH24:MI:SS));
end;
begin
execute dbms_logmnr.start_logmnr(Options => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG ,startscn => 3231808,endscn => 3231813);
end;
4.查看相应的日志信息
select username,scn,timestamp,sql_redo,sql_undo from v$logmnr_contents t where t.USERNAME='HXL' and sql_redo like '%T5%'
5.关闭logminer
begin
dbms_logmnr.end_logmnr;
end;
---------------------------------采用文件的方式----------------------------------------
1、配置LogMiner文件夹
create directory utlfile AS '/u01/app/oracle/logmnr';
alter system set utl_file_dir='/u01/app/oracle/logmnr' scope=spfile;
注意12c已经废除了该参数,可以不用设置该参数了
2.重启数据库
shutdown immediate
startup
SQL> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
utl_file_dir该参数已经过时废弃了
alter pluggable database all open;
3.创建字典文件
需要以DBA用户登录,创建到上面配置好的LogMiner文件夹中。
begin
dbms_logmnr_d.build(dictionary_filename => 'logminer01.ora',dictionary_location =>'UTLFILE',options => dbms_logmnr_d.store_in_flat_file);
end;
4.添加需要分析的归档日志文件
begin
dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/archlog/1_1206_1032346838.dbf',options=>dbms_logmnr.new);
end;
/
begin
dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/archlog/1_1207_1032346838.dbf',options=>dbms_logmnr.addfile);
end;
/
begin
dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/archlog/1_1208_1032346838.dbf',options=>dbms_logmnr.addfile);
end;
/
5.开始日志分析
begin
dbms_logmnr.start_logmnr(dictfilename=>'/u01/app/oracle/logmnr/logminer01.ora');
end;
6.查看内容
select username,scn,timestamp,sql_redo,sql_undo from v$logmnr_contents
使用此种方法无法查询出普通用户,比如TEST中的相关数据,只能查询出sys中数据.