Oracle logmnr 日志挖掘一例
Oracle logmnr 日志挖掘一例,使用logmnr来挖掘日志中的信息
1. 执行删除操作
SQL> drop table t ;
Table dropped.
SQL> select * from tab ;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$wWGJJd0UCrDgRAAMKRcWyg==$0 TABLE
TTS SYNONYM
TTSS SYNONYM
SQL> purge table t;
Table purged.
使用logmnr来挖掘日志中的信息
2. 查看操作目录
SQL> show parameter utl_file_dir
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string
没有指定,,那么指定一个文件夹用来存放logmnr的字典文件
-bash-3.00$ mkdir /gwrs/logmnr
SQL> alter system set utl_file_dir='/gwrs/logmnr' scope=spfile ;
System altered.
重启一下数据库
-bash-3.00$ srvctl stop database -d prod
-bash-3.00$ srvctl start database -d prod
3. 建立字典文件
SQL> execute dbms_logmnr_d.build ('dict.ora','/gwrs/logmnr',dbms_logmnr_d.store_in_flat_file);
PL/SQL procedure successfully completed.
4. 分析日志
将可能相关的日志都加入分析
begin
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_1_35_7wjflz93_.arc',options=>dbms_logmnr.new) ;
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_2_31_7wjfngtq_.arc',options=>dbms_logmnr.addfile) ;
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_2_32_7wjfnkbr_.arc',options=>dbms_logmnr.addfile) ;
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_1_36_7wjgg4dh_.arc',options=>dbms_logmnr.addfile) ;
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_1_37_7wjlnoxr_.arc',options=>dbms_logmnr.addfile) ;
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_1_38_7wjmwbcs_.arc',options=>dbms_logmnr.addfile) ;
dbms_logmnr.add_logfile(logfilename=>'/gwrs/PROD/archivelog/2012_06_01/o1_mf_2_33_7wjmwjfj_.arc',options=>dbms_logmnr.addfile) ;
dbms_logmnr.start_logmnr(dictfilename=>'/gwrs/logmnr/dict.ora');
end ;
/
5. 分析操作记录
注意, 这里的logmnr记录日志只在本次会话中生效,如果需要在其他会话分析这些日志需要创建一个表来保存它
create table logmnr_tmp tablespace users as select * from v$logmnr_contents ;
接下来就可以分析日志了。
SQL> col seg_name for a10
SQL> col sql_redo for a50
SQL> col seg_owner for a10
SQL> col table_name for a10
select scn , timestamp , seg_owner, seg_name , table_name , sql_redo from logmnr_tmp where table_name='T' ;
SCN TIMESTAMP SEG_OWNER SEG_NAME TABLE_NAME SQL_REDO
---------- --------- ---------- ---------- ---------- --------------------------------------------------
1823865 01-JUN-12 DEX T T ALTER TABLE "DEX"."T" RENAME TO "BIN$wWGJJd0UCrDgR
AAMKRcWyg==$0" ;
1823868 01-JUN-12 DEX T T drop table t AS "BIN$wWGJJd0UCrDgRAAMKRcWyg==$0"
;
1823953 01-JUN-12 DEX T T purge table "BIN$wWGJJd0UCrDgRAAMKRcWyg==$0" ;
如果发现username , os_username , machine_name 等为unknow 或者 null 的状态 这是一个bug 当你重复执行同一个logmnr使用相同的参数的时候就可能会出现这种状况(第一次不会)BUG:10129774
链接地址 https://support.Oracle.com/CSP/main/article?cmd=show&type=BUG&id=10129774
打补丁 10129774