GROUP# SEQUENCE# STATUS
---------- ---------- ----------------
1 10 INACTIVE
2 11 CURRENT
3 9 INACTIVE
SQL>
现在做任何操作都是的事物日志记录到第二个日志组的日志文件(current)
6.2、查看日志组成员
SQL> set linesize 120
SQL> col MEMBER format a45
SQL> select GROUP#,MEMBER from v$logfile;
GROUP# MEMBER
---------- ---------------------------------------------
3 /u01/app/oracle/oradata/or11g/redo03.log
2 /u01/app/oracle/oradata/or11g/redo02.log
1 /u01/app/oracle/oradata/or11g/redo01.log
SQL>
6.3、模拟误操作:
SQL> alter user scott account unlock identified by oracle;
User altered.
SQL> Update scott.emp set sal=0;
14 rows updated.
SQL> commit;
Commit complete.
SQL>
此时scott.emp表的工资都为0了,发现搞错了,需要恢复。
6.4、创建要挖掘的日志列表:
因为这里只有一个日志,那么只需要添加一个就好了(第一个日志用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');
execute dbms_logmnr.add_logfile(options =>dbms_logmnr.addfile,logfilename=>'/u01/app/oracle/oradata/or11g/redo03.log');
如:
SQL> execute dbms_logmnr.add_logfile(options =>dbms_logmnr.new,logfilename =>'/u01/app/oracle/oradata/or11g/redo01.log');
PL/SQL procedure successfully completed.
SQL> execute dbms_logmnr.add_logfile(options =>dbms_logmnr.addfile,logfilename=>'/u01/app/oracle/oradata/or11g/redo02.log');
PL/SQL procedure successfully completed.
SQL> execute dbms_logmnr.add_logfile(options =>dbms_logmnr.addfile,logfilename=>'/u01/app/oracle/oradata/or11g/redo03.log');
PL/SQL procedure successfully completed.
SQL>
说明:
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');
6.5、开始挖掘:
exec dbms_logmnr.start_logmnr(dictfilename=>'/u03/dfdict.data');
如:
SQL> exec dbms_logmnr.start_logmnr(dictfilename=>'/u03/dfdict.data');
PL/SQL procedure successfully completed.
SQL>
6.6、查看结果(这个是查询到当初误操作的语句,是通过redo查出来的):
select sql_redo from v$logmnr_contents where seg_name='EMP';
如:
SQL> select sql_redo from v$logmnr_contents where seg_name='EMP';
SQL_REDO
------------------------------------------------------------------------------------------------------------------------
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7369' and "SAL" = '800' and ROWID = 'AAAR3xAAEAAAACXAAA';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7499' and "SAL" = '1600' and ROWID = 'AAAR3xAAEAAAACXAAB';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7521' and "SAL" = '1250' and ROWID = 'AAAR3xAAEAAAACXAAC';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7566' and "SAL" = '2975' and ROWID = 'AAAR3xAAEAAAACXAAD';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7654' and "SAL" = '1250' and ROWID = 'AAAR3xAAEAAAACXAAE';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7698' and "SAL" = '2850' and ROWID = 'AAAR3xAAEAAAACXAAF';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7782' and "SAL" = '2450' and ROWID = 'AAAR3xAAEAAAACXAAG';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7788' and "SAL" = '3000' and ROWID = 'AAAR3xAAEAAAACXAAH';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7839' and "SAL" = '5000' and ROWID = 'AAAR3xAAEAAAACXAAI';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7844' and "SAL" = '1500' and ROWID = 'AAAR3xAAEAAAACXAAJ';
update "SCOTT"."EMP" set "SAL" = '0' where "EMPNO" = '7876' and "SAL" = '1100' and ROWID = 'AAAR3xAAEAAAACXAAK';