Oracle logminer 分析redo log(TOAD与PLSQL)

Oracle logminer 分析redo log

Oracle 11g r2 RAC centos 6.5

 

设置时间格式

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') date_format from dual ;

查看数据库是否开启补全日志功能

select

SUPPLEMENTAL_LOG_DATA_MIN,

SUPPLEMENTAL_LOG_DATA_PK,

SUPPLEMENTAL_LOG_DATA_UI,

SUPPLEMENTAL_LOG_DATA_FK,

SUPPLEMENTAL_LOG_DATA_ALL from v$database;

开启补全日志

alter database add supplemental log data;

alter database add supplemental log data (primary key, unique,foreign key) columns;

再次查询检查是否开启

开启归档--详细见归档的开启

SQL> archive log list;

Database log mode        Archive Mode

Automatic archival        Enabled

Archive destination        +FRA/bol/arch

Oldest online log sequence     93

Next log sequence to archive   95

Current log sequence        95

配置LogMiner工具

SQL> show parameter UTL_FILE

 

NAME      TYPE  VALUE

------------------------------------ ----------- ------------------------------

utl_file_dir      string

1 利用toad自带的工具logminer

dml 操作

select *from TESTYHQ;

insert into TESTYHQ(id1,name1)values (2,'hq');

commit;

利用toadlogminer直接分析redo

select * from V$LOGFILE;

 

select group#,sequence#,bytes,members,status from v$log;

 

toad-database-diagnose-logminer

选择online logs,输入redo文件全路径,比如

 

 

+DATA/bol/onlinelog/group_2.258.990861405

再选择时间范围,选择过大的话,日志会有很多,完成后点击finish,直接生成记录

 

可以用sql进行筛选查看

 

select scn,timestamp,operation,seg_owner,seg_name,

 table_space,row_id,username,os_username,machine_name,

 session#,serial#,sql_redo,sql_undo from v$logmnr_contents where seg_owner='SDE';

 

几个关键字段,username,machine_name,session#,serial#,sql_redo,sql_undo,可以清楚的看见

scn,时间,操作内容,表名,操作的机器名字,和操作语句,以及undo内容

利用plsql进行分析

 

[root@rac1 /]# mkdir u02

[root@rac1 /]# chown oracle:oinstall /u02

alter system set utl_file_dir='/u02' scope=spfile; --需要重启db

 

SQL>  show parameter UTL_FILE

 

NAME      TYPE  VALUE

------------------------------------ ----------- ------------------------------

utl_file_dir      string  /u02

 

[root@rac1 admin]# ls dbmslm*

dbmslmd.sql  dbmslm.sql  dbmslms.sql

[root@rac1 admin]# pwd

/u01/app/11.2.0/grid/rdbms/admin

SQL> @/u01/app/11.2.0/grid/rdbms/admin/dbmslmd.sql

SQL> @/u01/app/11.2.0/grid/rdbms/admin/dbmslm.sql

SQL> @/u01/app/11.2.0/grid/rdbms/admin/dbmslms.sql

 

SQL> execute dbms_logmnr_d.build(dictionary_filename =>'dfdict.data',dictionary_location =>'/u02');

 

PL/SQL procedure successfully completed.

--- 如果报错,请检查目录及权限

*

ERROR at line 1:

ORA-01336: specified dictionary file cannot be opened

ORA-29283: invalid file operation

ORA-06512: at "SYS.UTL_FILE", line 536

ORA-29283: invalid file operation

ORA-06512: at "SYS.DBMS_LOGMNR_INTERNAL", line 6110

ORA-06512: at "SYS.DBMS_LOGMNR_INTERNAL", line 6200

ORA-06512: at "SYS.DBMS_LOGMNR_D", line 12

ORA-06512: at line 1

--

insert into TESTYHQ(id1,name1)values (444,'hq');

commit;

 

select group#,sequence#,bytes,members,status from v$log;

select * from V$LOGFILE;

SQL> alter system switch logfile;

----

因为这里只有一个日志,那么只需要添加一个就好了(第一个日志用new=>dbms_logmnr.new)

execute dbms_logmnr.add_logfile(options =>dbms_logmnr.new,logfilename =>'/u01/app/oracle/oradata/or11g/redo01.log');

如果是有多个日志,那么就继续添加(添加其他日志用add=>dbms_logmnr.addfile)

execute dbms_logmnr.add_logfile(options =>dbms_logmnr.addfile,logfilename=>'/u01/app/oracle/oradata/or11g/redo02.log');

 

dbms_logmnr.new --用于建一个日志分析表

dbms_logmnr.addfile --用于加,入用于分析的日志文件

dbms_logmnr.removefile --用于移出,用于分析的日志文件

如果是删除日志就用removefile,如:

execute dbms_logmnr.add_logfile(options =>dbms_logmnr.removefile,logfilename =>'/u01/app/oracle/oradata/or11g/redo03.log');

---

SQL> alter system switch logfile;

 

System altered.

 

SQL> exec dbms_logmnr.add_logfile('+DATA/bol/onlinelog/group_1.257.990861405',dbms_logmnr.new);

 

PL/SQL procedure successfully completed.

 

SQL> exec dbms_logmnr.start_logmnr(dictfilename=>'/u02/dfdict.data');

 

PL/SQL procedure successfully completed.

 

 

select scn,timestamp,operation,seg_owner,seg_name,

 table_space,row_id,username,os_username,machine_name,

 session#,serial#,sql_redo,sql_undo from v$logmnr_contents where seg_owner='SDE';

 

create table t01 as select scn,timestamp,operation,seg_owner,seg_name,

 table_space,row_id,username,os_username,machine_name,

 session#,serial#,sql_redo,sql_undo from v$logmnr_contents where seg_owner='SDE';

 

--v$logmnr_contents 针对于session,其他session执行该查询就会报错

ORA-01306: 在从 v$logmnr_contents 中选择之前必须调用 dbms_logmnr.start_logmnr()

 

 select *from t01;

SQL> exec dbms_logmnr.end_logmnr;--关闭日志挖掘

PL/SQL procedure successfully completed.

 select *from t01;

 

posted @ 2018-11-13 15:05  春困秋乏夏打盹  阅读(2450)  评论(0编辑  收藏  举报