誤刪除了部分重要數據,已提交,需要恢復。首先嘗試flashback query閃回數據。資料庫運行在歸檔模式,首先確認資料庫的SCN的變化:SQL> col fscn for 999999999999999999999SQL> col nscn for 999999999999999999999SQ ...
誤刪除了部分重要數據,已提交,需要恢復。
首先嘗試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表確認,向當前表補回誤刪除的數據,至此閃回恢覆成功。沒有閃回特性的話,需要通過物理備份執行不完全恢復,或者找出足夠及時的邏輯備份來進行恢復,其過程都可能是極其複雜的。