共计 2139 个字符,预计需要花费 6 分钟才能阅读完成。
误删除了 Oracle 部分重要数据,已提交,需要恢复。首先尝试 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 表确认,向当前表补回误删除的数据,至此闪回恢复成功。没有闪回特性的话,需要通过物理备份执行不完全恢复,或者找出足够及时的逻辑备份来进行恢复,其过程都可能是极其复杂的。
更多 Oracle 相关信息见 Oracle 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=12