[20160805]logminer使用问题1.txt
--前一阵子看itpub有人想通过logminer来抽取归档同步数据库,实际上这个非常不科学,存在一定的风险,我觉得很多情况下会漏掉一些sql
--语句,通过例子来说明。
--首先说明logminer用来补救一些异常操作还是可行的。
1.测试环境说明:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SCOTT@book> alter database add supplemental log data;
Database altered.
SCOTT@book> alter database FORCE LOGGING ;
Database altered.
SCOTT@book> select SUPPLEMENTAL_LOG_DATA_MIN, FORCE_LOGGING from v$database ;
SUPPLEME FOR
-------- ---
YES YES
SCOTT@book> create table emp1 as select * from emp;
Table created.
--//安全期间,我还重启数据库。
2.测试1:
SCOTT@book> alter system archive log current ;
System altered.
SCOTT@book> @ &r/logfile
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME GROUP# STATUS TYPE MEMBER IS_
------ ------- --------- ----------- --------- ------- --- ---------- ------------- ------------------- ------------ ------------------- ------ ---------- ---------- ---------------------------- ---
1 1 409 52428800 512 1 YES INACTIVE 13245358514 2016-08-04 22:00:11 13245368452 2016-08-05 01:10:33 1 ONLINE /mnt/ramdisk/book/redo01.log NO
2 1 410 52428800 512 1 YES ACTIVE 13245368452 2016-08-05 01:10:33 13245387345 2016-08-05 09:40:07 2 ONLINE /mnt/ramdisk/book/redo02.log NO
3 1 411 52428800 512 1 NO CURRENT 13245387345 2016-08-05 09:40:07 2.814750E+14 3 ONLINE /mnt/ramdisk/book/redo03.log NO
--当前使用/mnt/ramdisk/book/redo03.log。
--做一个"极端"测试,修改后不提交看看:
SCOTT@book> update emp1 set ename=upper('1234567def') ;
14 rows updated.
SCOTT@book> alter system archive log current ;
System altered.
--分析这个归档日志。
$ ls -l /u01/app/oracle/archivelog/book/
total 161600
-rw-r----- 1 oracle oinstall 47642112 2016-08-04 12:19:16 1_407_907434361.dbf
-rw-r----- 1 oracle oinstall 41338880 2016-08-04 22:00:11 1_408_907434361.dbf
-rw-r----- 1 oracle oinstall 38933504 2016-08-05 01:10:33 1_409_907434361.dbf
-rw-r----- 1 oracle oinstall 37357568 2016-08-05 09:40:07 1_410_907434361.dbf
-rw-r----- 1 oracle oinstall 9216 2016-08-05 09:41:47 1_411_907434361.dbf
$ strings /u01/app/oracle/archivelog/book/1_411_907434361.dbf | grep 1234567DEF | head -1
1234567DEF
--//使用logminer分析:
Begin
SYS.DBMS_LOGMNR.ADD_LOGFILE( '/u01/app/oracle/archivelog/book/1_411_907434361.dbf', sys.dbms_logmnr.New);
end;
Begin
SYS.DBMS_LOGMNR.START_LOGMNR ( Options => sys.dbms_logmnr.DICT_FROM_ONLINE_CATALOG+sys.dbms_logmnr.COMMITTED_DATA_ONLY);
end;
--我使用sys.dbms_logmnr.COMMITTED_DATA_ONLY选项。也就是要提交才能显示。
SCOTT@book> select *from v$logmnr_contents where seg_name='EMP1' order by 1;
no rows selected
--//连影子都看不到,因为我在这个归档日志中没有提交。如果我换成如下:
Begin
SYS.DBMS_LOGMNR.START_LOGMNR ( Options => sys.dbms_logmnr.DICT_FROM_ONLINE_CATALOG);
end;
SCOTT@book> Select sql_undo From V$LOGMNR_CONTENTS where seg_name='EMP1' and rownum=1 ;
SQL_UNDO
----------------------------------------------------------------------------------------------------------
update "SCOTT"."EMP1" set "ENAME" = 'SMITH' where "ENAME" = '1234567DEF' and ROWID = 'AAAXY4AAEAAAAIzAAA';
--//你敢这样抽取吗?如果下一个归档的时间段执行的是rollback,你如何确定呢?
3.测试2:
--现在提交看看呢?
SCOTT@book> commit ;
Commit complete.
SCOTT@book> alter system archive log current ;
System altered.
Begin
SYS.DBMS_LOGMNR.ADD_LOGFILE( '/u01/app/oracle/archivelog/book/1_411_907434361.dbf', sys.dbms_logmnr.New);
end;
Begin
SYS.DBMS_LOGMNR.ADD_LOGFILE( '/u01/app/oracle/archivelog/book/1_412_907434361.dbf', sys.dbms_logmnr.AddFile);
end;
--//注意第2个使用sys.dbms_logmnr.AddFile。
Begin
SYS.DBMS_LOGMNR.START_LOGMNR ( Options => sys.dbms_logmnr.DICT_FROM_ONLINE_CATALOG+sys.dbms_logmnr.COMMITTED_DATA_ONLY);
end;
SCOTT@book> Select sql_undo From V$LOGMNR_CONTENTS where seg_name='EMP1' and rownum=1 ;
SQL_UNDO
----------------------------------------------------------------------------------------------------------
update "SCOTT"."EMP1" set "ENAME" = 'SMITH' where "ENAME" = '1234567DEF' and ROWID = 'AAAXY4AAEAAAAIzAAA';
--这样才能显示。所以使用它来抽取同步其他数据库是存在一些问题的。不建议使用。