数据恢复实战:oracle delete误删除表数据后的恢复过程

1、根据时间进行恢复

此种方式需要我们大致知道执行delete语句的时间。

查询系统当前时间:select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss’) from dual;

假设在2022-04-02 16:27:11分钟,执行了删除语句
delete from demo ;

此时已经表中不能查询到数据了。我们知道delete执行的时间,往前推1分钟(delete执行时间之前都可以,越小越好,本例以1分钟为例),执行如下语句

select * from DEMO as of timestamp to_timestamp(‘2022-04-02 16:26:11′,‘yyyy-mm-dd hh24:mi:ss’);

可以看到虽然当前demo表中没有数据,但是可以查询到demo表前1分钟时候的数据。

恢复1:此时可以通过plsql工具的导出查询结果功能导出sql文件,然后在重新执行sql文件中的insert语句进行数据恢复。

恢复2:执行以下sql进行数据恢复:

flashback table DEMO to timestamp to_timestamp(‘2022-04-02 16:26:11′,‘yyyy-mm-dd hh24:mi:ss’);

如果报错ORA-08189:未启用行移动功能,不能闪回表

则执行:

alter table DEMO enable row movement;

添加表行移动功能后,在进行flashback语句进行恢复

如果报错: ORA-08194: 在实体化视图上不允许闪回表操作;则通过下面介绍的新建临时表的方式进行恢复。

恢复3(新建临时表):

新建demo1表,插入需要恢复的数据

create table DEMO1 as select * from DEMO as of timestamp to_timestamp(‘2022-04-02 16:30:11′,‘yyyy-mm-dd hh24:mi:ss’);

将demo1表的数据恢复到demo表中

insert into DEMO select * from DEMO1 where not exists (select * from DEMO where DEMO.id=DEMO1.id);

恢复4(根据scn恢复):

查询当前的scn号

select current_scn from v$database;

将scn号减少若干,执行下语句,直到能查看到我们delete的数据为止

select * from DEMO as of scn 166937913;

通过合适的scn号,执行下sql语句进行数据恢复

flashback table DEMO to scn 166937913;

总结

到此这篇关于oracle delete误删除表数据后如何恢复的文章就介绍到这了,更多相关oracle delete误删表数据恢复内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


数据运维技术 » 数据恢复实战:oracle delete误删除表数据后的恢复过程