1 flashback database (闪回数据库)
2 Flashback Table (闪回表)
3 Flashback Drop (闪回删除)
4 Flashback Query(闪回查询)
4.1 Flashback Table Query(闪回表查询)
4.2 Flashback Version Query(闪回版本查询)
4.3 Flashback Transaction Query(闪回事务查询)
闪回表 FLASH BACK TALBE
通过查询UNDO段来抽取所有已变化的记录细节,在此基础之上再构造和执行能够倒退这些变化的语句,表闪回通过执行倒退变化的语句并且该执行是一个事务,所有常用规则在该事务上起作用。 表闪回时,表上的触发器缺省被禁用,即该表上的DML触发器将暂时失效,可以在闪回时指定触发器是否失效。 表闪回需要启用表上的记录转移选项.
a.用户必须具有flashback any table系统权限或flashback对象权限
b.用户必修在表上具有select insert delete和alter权限
c.必须合理设置初始化参数undo_retention,以确保UNDO信息保留足够时间
d.必须激活行移动特征:alter table table_name enable row movement;
--基于SCN的表闪回
FLASHBACK TABLE <schema_name.table_name> TO SCN <scn_number> [<ENABLE | DISABLE> TRIGGERS]
--基于TIMESTAMP的表闪回
FLASHBACK TABLE <schema_name.table_name> TO TIMESTAMP <timestamp> [<ENABLE | DISABLE> TRIGGERS]
--基于RESTORE POINT的表闪回
FLASHBACK TABLE <schema_name.table_name> TO RESTORE POINT <restore_point> [<ENABLE | DISABLE> TRIGGERS]
alter table tb_emp enable row movement; --开启表tb_emp表的row movement 功能
--插入deptno为20的员工
insert into tb_emp
select empno,ename,job,deptno from scott.emp where deptno=20;
commit;
select current_scn,systimestamp from v$database; --获取系统当前的SCN
flashback table tb_emp to scn 661521; --将表闪回到scn为,即插入部门号为的记录之前
flashback table tb_emp to timestamp to_timestamp('01-JAN-11 10.56.28.733000');
演示基于RESTORE POINT的表闪回
基于RESTORE POINT的表闪回首先要创建适当的闪回点,创建闪回点的方式为
CREATE RESTORE POINT point_name;
对于闪回成功之后,无用的闪回点可以及时删除掉,删除闪回点的方式为
DROP RESTORE POINT point_name
下面对基于RESTORE POINT 闪回进行演示
create restore point zero; --创建闪回点zero
insert into tb_emp --插入deptno为10的员工
select empno,ename,job,deptno from scott.emp where deptno=10;
commit;
flashback table tb_emp to restore point zero; --闪回到闪回点one之前
drop restore point zero;
.表闪回的几个常见问题
a.当闪回删除操作之前,如果某个键值如主键被重用,将导致违反主键约束,闪回失败。
b.若闪回所需要的UNDO信息不存在,将引发
ORA-08180:no snapshot found based on specified time(未找到基于指定时间的快照)错误
c.如果受闪回影响的记录被其它用户锁定,将引发
ORA-00054:resource busy and acquire with NOWAIT specified (资源忙碌)错误
d.表定义在闪回期间不能发生变化,否则导致
ORA-01466:unable to read data - table definition has changed(表定义已变化)错误
e.闪回前未启用row movement,
将收到ORA-08189: cannot flashback the table because row movement is not enabled 错误
f.对于存在参照关系的情况,建议将主表等一起实施闪回,否则,将收到ORA-02091: transaction rolled back,ORA-02291错误
g.SYS 模式中的表不能使用表闪回技术