1.创建目录
mkdir /u01/app/oracle/flash
2.配置FRA
alter system set db_recovery_file_dest_size=15G;
alter system set db_recovery_file_dest='/u01/app/oracle/flash';
3.设置闪回参数--确保可以闪回48h内的数据库
alter system set db_flashback_retention_target=2880;
4.开闪回
alter database flashback on;
实践:闪回部分数据
1.解锁hr账户连接数据库
alter user hr identified by hr account unlock;
2.运行脚本
在这个脚本中,有两个事务,我们尝试保留insert的事务,回滚update的事务。
conn hr/hr@prod4
insert into departments values(290,'Poduct Sales',114,1800);
insert into departments values(300,'Busses Sales',203,1700);
insert into departments values(280,'Mac Sales',205,1700);
commit;
--update
update departments set department_id=310 where department_id=300;
update departments set department_name='Iphone sales' where department_id=280;
commit;
3.闪回版本查询
SELECT versions_xid XID, versions_startscn START_SCN,
versions_endscn END_SCN, versions_operation OPERATION,
department_id,department_name
FROM departments
VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE;
可以看到最下面的几行是刚才执行脚本所做的操作。
3.启用行移动
alter table departments enable row movement;
4.指定scn号闪回表
flashback table departments to scn 2148345;