當我們不小心誤操作致使數據庫數據丟失、改變時, 需要對數據庫對象做基於時間點的恢復,找到我們需要的數據,這個時間點不能認為精確確定,我們可以通過對oracle日志進行分析,而獲得無操作的精確時間點。
oracle db提供了一個分析日志包logmnr
logminer 工具的使用
-------對redo log 進行挖掘,找出在某個時間點所作的DDL 或DML 操作(包括:時間點、datablock scn 、sql語句)
實驗測試
SQL> select name from v$archived_log; NAME -------------------------------------------------- /oracle/arch1/1_2_883536782.dbf SQL> SQL> SQL> delete from scott.t1; 576 rows deleted. SQL> alter system archive log current; System altered. SQL> create table scott.t6 as select * from scott.emp; Table created. SQL> alter system archive log current; System altered. SQL> select name from v$archived_log; NAME -------------------------------------------------- /oracle/arch1/1_2_883536782.dbf /oracle/arch1/1_3_883536782.dbf /oracle/arch1/1_4_883536782.dbf
--啟動log miner添加要分析的日志
SQL> execute dbms_logmnr.add_logfile(logfilename=>'/oracle/arch1/1_2_883536782.dbf',options=>dbms_logmnr.new); PL/SQL procedure successfully completed.
--添加需要分析的日志
SQL> execute dbms_logmnr.add_logfile(logfilename=>'/oracle/arch1/1_3_883536782.dbf',options=>dbms_logmnr.addfile); PL/SQL procedure successfully completed. SQL> execute dbms_logmnr.add_logfile(logfilename=>'/oracle/arch1/1_4_883536782.dbf',options=>dbms_logmnr.addfile) PL/SQL procedure successfully completed.
--執行log miner
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='T1'; USERNAME SCN TIMESTAMP ------------------------------ ---------- ------------------- SQL_REDO -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- delete from "SCOTT"."T1" where "EMPNO" = '7782' and "ENAME" = 'CLARK' and "JOB" = 'MANAGER' and "MGR" = '7839' and "HIREDATE" = TO_DATE('1981-06-09 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and "SAL" = '245 0' and "COMM" IS NULL and "DEPTNO" = '10' and ROWID = 'AAAVbSAAFAAAACXABi'; SYS 1494545 2015-06-28 04:24:44 delete from "SCOTT"."T1" where "EMPNO" = '7839' and "ENAME" = 'KING' and "JOB" = 'PRESIDENT' and "MGR" IS NULL and "HIREDATE" = TO_DATE('1981-11-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and "SAL" = '500 0' and "COMM" IS NULL and "DEPTNO" = '10' and ROWID = 'AAAVbSAAFAAAACXABj'; SYS 1494545 2015-06-28 04:24:44 delete from "SCOTT"."T1" where "EMPNO" = '7844' and "ENAME" = 'TURNER' and "JOB" = 'SALESMAN' and "MGR" = '7698' and "HIREDATE" = TO_DATE('1981-09-08 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and "SAL" = '1 。。。。。
--結束log miner 分析
SQL> execute dbms_logmnr.end_logmnr; PL/SQL procedure successfully completed.
以上就是本文的全部內容,希望大家可以喜歡。