标签:ble format dmi read outline logfile redo log bsp 数据字典
logminer 工具的使用
——对redo log 进行挖掘,找出在某个时间点所作的DDL 或DML 操作(包括:时间点、datablock scn 、sql语句)
1) 对DML 分析
SYS @ prod > select * from scott.tb01;
ID
----------
111
222
333
SQL> delete from scott.tb01;
3 rows deleted.
SQL> commit;
Commit complete.
SQL> insert into scott.tb01 values(1);
1 row created.
SQL> insert into scott.tb01 values(2);
1 row created.
SQL> insert into scott.tb01 values(3);
1 row created.
SQL> commit;
Commit complete.
SYS @ prod > select * from scott.tb01;
ID
----------
1
2
3
——查看当前日志组
SYS @ prod > select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 43 52428800 1 YES INACTIVE 837798 15-DEC-12
2 1 44 52428800 1 YES INACTIVE 852508 01-MAR-13
3 1 45 52428800 1 NO CURRENT 872875 01-MAR-13
SQL> alter system archive log current; ——使当前日志组归档
System altered.
SYS @ prod > select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 46 52428800 1 NO CURRENT 873198 01-MAR-13
2 1 44 52428800 1 YES INACTIVE 852508 01-MAR-13
3 1 45 52428800 1 YES ACTIVE 872875 01-MAR-13
*********************************以上接案例1***********************************
2) 启用logmnr
——添加database补充日志
SYS @ prod > alter database add supplemental log data; ——不添加后面会出错
Database altered.
——查询日志(归档日志和当前日志)
SYS @ prod > select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 46 52428800 1 NO CURRENT 873198 01-MAR-13
2 1 44 52428800 1 YES INACTIVE 852508 01-MAR-13
3 1 45 52428800 1 YES ACTIVE 872875 01-MAR-13
SQL> select member from v$logfile;——当前日志
MEMBER
--------------------------------------------------
/u01/app/oracle/oradata/prod/redo01.log
/u01/app/oracle/oradata/prod/redo02.log
/u01/app/oracle/oradata/prod/redo03.log
SQL> select name from v$archived_log;——查看归档日志信息
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2012_12_15/o1_mf_1_42_8dq63fpg_.arc
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_43_8lz88430_.arc
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_44_8lz8xwqz_.arc
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_45_8lz9fqxg_.arc
——添加日志,分析【添加的日志应该是切换前的日志,归档日志是最后一个日志】
SYS @ prod > execute dbms_logmnr.add_logfile(logfilename=>‘/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_45_8lz9fqxg_.arc‘,options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SYS @ prod > execute dbms_logmnr.add_logfile(logfilename=>‘/u01/app/oracle/oradata/prod/redo03.log‘,options=>dbms_logmnr.addfile);
PL/SQL procedure successfully completed.
——执行logmnr 分析
SQL> execute dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);
PL/SQL procedure successfully completed.
——查询分析结果
SQL> alter session set nls_date_format=‘yyyy-mm-dd hh24:mi:ss‘;
Session altered.
SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents where seg_name=‘TB01‘;
USERNAME SCN TIMESTAMP SQL_REDO
--------------- ---------- ------------------- --------------------------------------------------
849589 2012-03-22 17:31:08 delete from "SCOTT"."TB01" where "ID" = ‘1‘ and RO
WID = ‘AAACc0AAFAAAAAYAAA‘;
849589 2012-03-22 17:31:08 delete from "SCOTT"."TB01" where "ID" = ‘2‘ and RO
WID = ‘AAACc0AAFAAAAAYAAB‘;
849589 2012-03-22 17:31:08 delete from "SCOTT"."TB01" where "ID" = ‘3‘ and RO
WID = ‘AAACc0AAFAAAAAYAAC‘;
849599 2012-03-22 17:31:35 insert into "SCOTT"."TB01"("ID") values (‘111‘);
849621 2012-03-22 17:32:41 insert into "SCOTT"."TB01"("ID") values (‘222‘);
849623 2012-03-22 17:32:47 insert into "SCOTT"."TB01"("ID") values (‘333‘);
——结束日志分析
SQL> execute dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
2) 对DDL 操作分析
SCOTT @ prod > drop table tb01;
Table dropped.
SCOTT @ prod > create table tb01(id int) tablespace users;
Table created.
SCOTT @ prod > insert into tb01 values(1);
1 row created.
SCOTT @ prod > commit;
Commit complete.
——设置logmnr 参数,存放数据字典文件
[oracle@ogg admin]$ mkdir -p /home/oracle/logmnr
SYS @ prod > show parameter utl;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
create_stored_outlines string
utl_file_dir string
SYS @ prod > alter system set utl_file_dir=’/home/oracle/logmnr‘ scope=spfile;
System altered.
SYS @ prod >startup force
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 79693200 bytes
Database Buffers 230686720 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SYS @ prod >show parameter utl
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
create_stored_outlines string
utl_file_dir string /export/home/oracle/logmnr
——建立数据字典文件dict.ora
SYS @ prod >execute dbms_logmnr_d.build(‘dict.ora‘,‘/home/oracle/logmnr‘,dbms_logmnr_d.store_in_flat_file);
PL/SQL procedure successfully completed.
——查看日志信息
SQL> select name,sequence# from v$archived_log;
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_44_8lz8xwqz_.arc
44
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_45_8lz9fqxg_.arc
45
/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_46_8lzb48og_.arc
46
SYS @ prod > select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 46 52428800 1 YES INACTIVE 873198 01-MAR-13
2 1 47 52428800 1 NO CURRENT 893931 01-MAR-13
3 1 45 52428800 1 YES INACTIVE 872875 01-MAR-13
SYS @ prod > select group#,member from v$logfile;
GROUP# MEMBER
---------- --------------------------------------------------
1 /u01/app/oracle/oradata/prod/redo01.log
2 /u01/app/oracle/oradata/prod/redo02.log
3 /u01/app/oracle/oradata/prod/redo03.log
——添加日志分析
SYS @ prod > execute dbms_logmnr.add_logfile(logfilename=>‘/u01/app/oracle/oradata/prod/redo02.log‘,options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
SYS @ prod > execute dbms_logmnr.add_logfile(logfilename=>‘/u01/app/oracle/flash_recovery_area/PROD/archivelog/2013_03_01/o1_mf_1_46_8lzb48og_.arc‘,options=>dbms_logmnr.addfile);
PL/SQL procedure successfully completed.
——执行分析
SYS @ prod >execute dbms_logmnr.start_logmnr(dictfilename=>‘/home/oracle/logmnr/dict.ora‘,options=>dbms_logmnr.ddl_dict_tracking);
PL/SQL procedure successfully completed.
——查看分析结果
SYS @ prod >alter session set nls_date_format=‘yyyy-mm-dd hh24:mi:ss‘;
Session altered.
SYS @ prod >select username,scn,timestamp,sql_redo from v$logmnr_contents where username=‘SCOTT‘ and lower(sql_redo) like ‘%table%‘;
USERNAME SCN TIMESTAMP SQL_REDO
---------- ---------- ------------------- --------------------------------------------------
SCOTT 851229 2012-03-23 15:45:22 drop table tb01 purge;
SCOTT 851264 2012-03-23 15:45:45 create table tb01(id int) tablespace test;
SQL> execute dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
***********************************以上接案例2*****************************
标签:ble format dmi read outline logfile redo log bsp 数据字典
原文地址:http://www.cnblogs.com/iyoume2008/p/7784814.html