flashback query閃回資料

子魚猴發表於2018-05-28

誤刪除了部分重要資料,已提交,需要恢復。
首先嚐試flashback query閃回資料。

資料庫執行在歸檔模式,首先確認資料庫的SCN的變化:

SQL> col fscn for 999999999999999999999
SQL> col nscn for 999999999999999999999
SQL> select name,first_change# fscn,next_change# nscn, first_time from v$archived_log;

NAME                                             FSCN     NSCN FIRST_TIME
—————————————————————————– ———– ———– ——————
/u01/app/oracle/fast_recovery_area/CDB/CDB/archivelog/2018_05_28/o1_mf_1_3_fj      1547949     1550763 2018:05:2816:37:41
qj6z9t_.arc

/u01/app/oracle/fast_recovery_area/CDB/CDB/archivelog/2018_05_28/o1_mf_1_4_fj      1550763     1551171 2018:05:2816:42:07
qjsm3t_.arc

/u01/app/oracle/fast_recovery_area/CDB/CDB/archivelog/2018_05_28/o1_mf_1_5_fj      1551171     1551255 2018:05:2816:52:03
qjwkog_.arc

/u01/app/oracle/fast_recovery_area/CDB/CDB/archivelog/2018_05_28/o1_mf_1_6_fj      1551255     1551654 2018:05:2816:53:37
qjxycd_.arc

獲取當前的SCN:
SQL> select dbms_flashback.get_system_change_number  fscn from dual;

          FSCN
———————-
           1551702
           

使用應用使用者嘗試閃回:
SQL> conn c##scott/tiger
Connected.

           
現有資料:
SQL> select count(*) from emp1;

  COUNT(*)
———-
     0

建立恢復表:
SQL> create table emp1_recov as select * from emp1 where 1=0;

Table created.

根據業務提供的大致誤操作時間,結合V$ARCHIVED_LOG檢視,選擇適當SCN向前執行閃回查詢:
 
SQL> select count(*) from emp1 as of scn 1551171;
select count(*) from emp1 as of scn 1551171
                     *
ERROR at line 1:
ORA-01466: unable to read data – table definition has changed

嘗試多個SCN,獲取最佳值(能知道具體時間,那麼可以獲取準確的資料恢復):

SQL> select count(*) from emp1 as of scn 1551255;

  COUNT(*)
———-
    14

SQL> select count(*) from emp1 as of scn 1551200;
select count(*) from emp1 as of scn 1551200
                     *
ERROR at line 1:
ORA-01466: unable to read data – table definition has changed

SQL> select count(*) from emp1 as of scn 1551233;
select count(*) from emp1 as of scn 1551233
                     *
ERROR at line 1:
ORA-01466: unable to read data – table definition has changed

SQL> select count(*) from emp1 as of scn 1551244;

  COUNT(*)
———-
    14

最後選擇恢復到SCN為1551244的時間點,程式碼如下:
SQL> insert into emp1_recov select * from emp1 as of scn 1551244;

14 rows created.

SQL> commit;

Commit complete.

由業務人員通過emp1_recov表確認,向當前表補回誤刪除的資料,至此閃回恢復成功。沒有閃回特性的話,需要通過物理備份執行不完全恢復,或者找出足夠及時的邏輯備份來進行恢復,其過程都可能是極其複雜的。

          

相關文章