Oracle日志挖掘小结

一、安装logminer

$ORACLE_HOME/rdbms/admin/dbmslm.sql

$ORACLE_HOME/rdbms/admin/dbmslmd.sql

通常在安装数据库后就已经安装了Logminer,要查看数据库是否安装了LogMiner,只需查看数据库中是否已经有了dbms_logmnr和dbms_logmnr_d这2个package,如果有了,则已经安装。

如果没有,则需要通过两个脚本须用DBA用户身份运行。第1个脚本用来创建dbms_logmnr包,该包用来分析日志文件,第2个脚本用来创建dbms_logmnr_d包,该包用来创建数据字典文件。

创建完成后数据库中将多出4个procedure和3个view,具体如下:

  1. dbms_logmnr_d.build :创建一个数据字典文件;

  2. dbms_logmnr.add_logfile :添加日志文件以供分析;

  3. dbms_logmnr.start_logmnr :开始分析日志文件;

  4. dbms_logmnr.end_logmnr :结束分析日志文件;

1.v$logmnr_dictionary :显示字典文件的信息;

2.logmnr_logs :在LogMiner启动时显示要分析的日志列表;

3.logmnr_contents :Logminer启动后,可以使用该view查看日志文件的内容。

需要注意,这里的view是session相关,其它session是查看不到的,仅仅可以在当前session中查看。

二、开启数据库的归档默认 (被分析的数据库)

archive log list;

三、添加归档日志

BEGIN

dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48238_983987043.dbf',options=>dbms_logmnr.NEW);

END;

/

--第一次添加是

dbms_logmnr.add_logfile(logfilename=>'/home/app/oracle/oradata/orcl/arch_log/1_51_936489730.dbf',options=>dbms_logmnr.ADDFILE);

END;

/

--新增的需要addfile

BEGIN

dbms_logmnr.add_logfile(logfilename=>'/home/app/oracle/oradata/orcl/arch_log/1_50_936489730.dbf',options=>dbms_logmnr.ADDFILE);

END;

/

四、使用logmnr分析

EXECUTE dbms_logmnr.start_logmnr();

begin

dbms_logmnr.start_logmnr();

end;

/

EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);

---指定外部数据字典

五、查看日志分析内容

注意:这个视图应该是外部表或者内存中的数据,如果需要长期留存,可以使用CTAS将结果保存到数据库中。

create table logmnr_210301 as select * from v$logmnr_contents;

select * from v$logmnr_contents;

v$logmnr_contents的部分栏位信息:

栏位 解释


SCN 查询的特定数据的SCN号

TIMESTAM 数据改变发生的时间

COMMIT_TIMESTAMP 数据改变提交的时间

SEG_OWNER 数据发生改变的段名称

SEG_NAME 段的所有者的名称

SEG_TYPE 数据发生改变的段类型

SEG_TYPE_NAME 数据发生改变的段类型名称

TABLE_SPACE 变化段的表空间

ROW_ID 数据变化行的ID

SESSION_INFO 数据发生变化时会话信息

OPERATION 日志中记录的操作

SQL_REDO 日志中记录的指定行变化的SQL语句(正向操作)

SQL_UNDO 为重做日志记录回退或恢复制定行变化的SQL语句

五、结束

begin

execute dbms_logmnr.end_logmnr();

end ;

/

执行该结束命令后,视图v$logmnr_contents中的数据丢弃了。

EXECUTE dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48238_983987043.dbf',options=>dbms_logmnr.NEW);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48178_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48231_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48204_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47050_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48207_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48237_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48191_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48222_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48193_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47062_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47032_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48229_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47035_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47033_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48232_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47034_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48230_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48177_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48198_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47079_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48205_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47069_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47056_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48217_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47041_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48215_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48209_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48186_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48218_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48188_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47036_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48208_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48197_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48227_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47080_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47059_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47074_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48180_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47073_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47057_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47028_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47044_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47077_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48192_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48221_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47042_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47045_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47085_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48199_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47081_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48210_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47029_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48176_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48194_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48225_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47051_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47078_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47048_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47070_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47068_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48202_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48189_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48226_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47037_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48224_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/1_48187_983987043.dbf',options=>dbms_logmnr.ADDFILE);

execute dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/rec/2_47076_983987043.dbf',options=>dbms_logmnr.ADDFILE);

相关推荐
百度智能云技术站5 小时前
广告投放系统成本降低 70%+,基于 Redis 容量型数据库 PegaDB 的方案设计和业务实践
数据库·redis·oracle
梦想平凡7 小时前
PHP 微信棋牌开发全解析:高级教程
android·数据库·oracle
夏木~9 小时前
Oracle 中什么情况下 可以使用 EXISTS 替代 IN 提高查询效率
数据库·oracle
吴冰_hogan10 小时前
MySQL InnoDB 存储引擎 Redo Log(重做日志)详解
数据库·oracle
CodeCraft Studio10 小时前
【实用技能】如何在 SQL Server 中处理 Null 或空值?
数据库·oracle·sqlserver
武汉联从信息10 小时前
浅谈ORACLE中间件SOA BPM,IDM,OID,UCM,WebcenterPortal服务器如何做迁移切换
oracle
Elastic 中国社区官方博客11 小时前
Elasticsearch:什么是查询语言?
大数据·数据库·elasticsearch·搜索引擎·oracle
夜光小兔纸12 小时前
oracle dblink 的创建及使用
数据库·oracle
Smile丶凉轩12 小时前
MySQL库的操作
数据库·mysql·oracle
p@nd@14 小时前
Oracle筑基篇-调度算法-LRU的引入
数据库·oracle·操作系统·lru