ORACLE恢复误删除数据

  今天手贱,把正式数据库中的一个表给清空了,天啦噜!!!晴天一声霹雳啊!!!

  幸好还有万能的百度,以下是几种恢复方法,属予随笔以记之。

一、通过时间恢复删除且已提交的数据

1、查询当前系统时间
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
2、查询删除数据的时间点的数据
select * from 表名 as of timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');  (如果不是,则继续缩小范围)
3、恢复删除且已提交的数据
flashback table 表名 to timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');
注意:如果在执行上面的语句,出现错误。可以尝试执行 alter table 表名 enable row movement; //允许更改时间戳

二、通过scn恢复删除且已提交的数据

1、获得当前数据库的scn号
select current_scn from v$database; (切换到sys用户或system用户查询) 
查询到的scn号为:1499223
2、查询当前scn号之前的scn
select * from 表名 as of scn 1499220; (确定删除的数据是否存在,如果存在,则恢复数据;如果不是,则继续缩小scn号)
3、恢复删除且已提交的数据
flashback table 表名 to scn 1499220;

三、借助临时表恢复删除且已提交的部分数据

1、查询删除数据的时间点数据
select * from tablename as of timestamp to_timestamp('2013-12-05 16:43:00','YYYY-MM-DD HH24:MI:SS'); 
2、将该时间点数据插入到临时表
create temp_a as select * from a as of timestamp to_timestamp('2013-12-05 16:43:00','YYYY-MM-DD HH24:MI:SS'); 
3、过滤出需要的数据恢复 
insert into a select * from temp_a where id = 1; 
4、删除临时表
drop table temp_a; 

TIPS:可恢复时间的查询与修改

1、查询命令show parameter undo;
命令查看当时的数据库参数undo_retention设置。
显示如下:
undo_management                       string       AUTO
undo_retention                        integer      10800
undo_suppress_errors                  boolean      FALSE
undo_tablespace                       string       UNDOTBS1
undo_retention(保持力),10800单位是秒。即3个小时。
2、修改默认的undo_retention参数设置
ALTER SYSTEM SET undo_retention=10800 SCOPE=BOTH;

 

posted @ 2016-09-27 09:55  月生丶  阅读(216)  评论(0)    收藏  举报