使用Flashback Query恢复误删除数据

使用Flashback Query恢复误删除数据:

误删除了部分重要数据,并且已经提交,需要恢复。这该怎么办?
首先尝试使用flashback query闪回数据。首先确认数据库的SCN变化:

sys@CCDB> col fscn for 9999999999999999
sys@CCDB> col nscn for 9999999999999999
sys@CCDB> select name,first_change# fscn,next_change# nscn,first_time from v$archived_Log where status = 'A';
NAME                                                       FSCN        NSCN FIRST_TIME
--------------------------------------------------- ----------- ----------- -------------------
/databak/ARCHIVELOG/ARC0000004623_0689837452.0001      73470545    73486056 2010-02-01 06:07:23
/databak/ARCHIVELOG/ARC0000004624_0689837452.0001      73486056    73500151 2010-02-01 07:43:11
/databak/ARCHIVELOG/ARC0000004625_0689837452.0001      73500151    73503996 2010-02-01 08:27:51
/databak/ARCHIVELOG/ARC0000004626_0689837452.0001      73503996    73514545 2010-02-01 08:28:23
/databak/ARCHIVELOG/ARC0000004627_0689837452.0001      73514545    73527235 2010-02-01 08:52:14
/databak/ARCHIVELOG/ARC0000004628_0689837452.0001      73527235    73540995 2010-02-01 09:25:19
/databak/ARCHIVELOG/ARC0000004629_0689837452.0001      73540995    73553760 2010-02-01 10:06:36
/databak/ARCHIVELOG/ARC0000004630_0689837452.0001      73553760    73567478 2010-02-01 10:43:23
8 rows selected.

当前的SCN为:

sys@CCDB> select dbms_flashback.get_system_change_number fscn from dual;
             FSCN
-----------------
         73574265

使用应用用户连接数据库尝试闪回:

sys@CCDB> conn username/password
Connected.

现有数据如下:

winks@CCDB> select count(*) from member;
  COUNT(*)
----------
   1267661

创建恢复表:

winks@CCDB> create table member_recov as select * from member where 1=0;
Table created.

选择合适的SCN向前恢复:

winks@CCDB> select count(*) from member as of scn 73566300;
  COUNT(*)
----------
   1297438

尝试多个SCN,获取最佳值(如果能得知具体时间,那么可以获得准确的数据闪回)。

winks@CCDB> select count(*) from member as of scn 73567300;
  COUNT(*)
----------
   1297466
winks@CCDB> select count(*) from member as of scn 73567478;
  COUNT(*)
----------
   1297469

最后选择恢复到SCN为73567478的时间点。

winks@CCDB> insert into member_recov select * from member as of scn 73567478;
1297469 rows created.
winks@CCDB> commit;
Commit complete.

经过确认,已经可以满足需要,找回误删除部分数据,至此闪回恢复成功完成。

- The End -

你可能感兴趣的:(flashback)