闪回查询

当oracle中的记录被误删除后,可通过闪回查询快速找回

一、前置需求

oracle 9i之后的版本,适用于delete语句,drop语句不适用

1、设置undo_management 管理方式为auto(默认方式),需要重启生效

alter system set undo_management ='auto' scope=spfile;

2、设置undo_retention的值,该值表示undo要保留的最长时间,即最长的可闪回的时间,单位s,该值会导致undo表空间增大,根据时间情况合理设置

alter system set undo_retention= 86400 scope=both ;

查看结果

select * from v$parameter where name like '%undo%'


二、模拟闪回查询:

1、正常的数据

select * from test

2、模拟删除

delete from test;

3、基于时间的闪回查询

基于多少分钟之前

select * from test as of timestamp (sysdate-2/1440)

基于某个时间点

select * from test as of timestamp to_timestamp('20191121 11:50:00' ,'yyyymmdd hh24:mi:ss')

4、保存闪回数据

insert into test  select * from test as of timestamp to_timestamp('20191121 11:50:00' ,'yyyymmdd hh24:mi:ss')

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。