oracle10g-flashback学习.docxVIP

  • 1
  • 0
  • 约9.84千字
  • 约 8页
  • 2018-01-02 发布于河南
  • 举报
oracle10g-flashback学习

Oracle10g Flashback 实践一、概述Flashback 是ORACLE 自9i 就开始提供的一项特性,在9i 中利用oracle 查询多版本一致的特点,实现从回滚段中读取表一定时间内操作过的数据,可用来进行数据比对,或者修正意外提交造成的错误数据,该项特性也被称为Flashback Query。在10g 中Flashback又得到了相当大的增强,利用Recycle Bin(回收站)和Flash Recovery Area(闪回区)的特性实现快速恢复删除表(Flashback Table)或做数据库时间点恢复(Flashback Database)的功能。要使用flashback 的特性,必须启用自动撤销管理表空间,不仅是flashback query,也包括flashback table 和flashback database,而对于后两项还会有些其它的附加条件,比如flashback table 需要启用了recycle bin(回收站),flashback database 还要求必须启用了flashback area(闪回区)。SQL show parameter undoNAME TYPE VALUE------------------------------------ ----------- ------------------------------undo_management string AUTOundo_retention integer 10800undo_tablespace string UNDOTBS1在一种情况下,undo 表空间能够确保undo 中的数据在undo_retention 指定时间过期前一定有效,就是为undo 表空间指定Retention Guarantee,指定之后,oracle 对于undo 表空间中未过期的undo 数据不会覆盖,例如:SQL Alter tablespace undotbs1 retention guarantee;如果想禁止undo 表空间retention guarantee,如例:SQL Alter tablespace undotbs1 retention noguarantee;二、Flashback Query(闪回查询)Flashback Query 是利用多版本读一致性的特性从UNDO 表空间读取操作前的记录数据!1、As of timestamp的示例SQL create table tab_test as select rownum id from dba_users;SQL delete from tab_test where id5;SQL commit;假设当前距离删除数据已经有3分钟左右的话:SQL select count(*) from tab_test as of timestamp sysdate-3/1440 where id10; SQL insert into tab_test select * from tab_test as of timestamp sysdate-3/1440 where id5; SQL commit;提示:as of timestamp|scn 的语法是自9iR2 后才开始提供支持,如果是9iR1 版本,需要使用DBMS_FLASHBACK包来应用flashback query 的特性。2、As of scn的示例如果需要对多个相互有主外键约束的表进行恢复时,如果使用as of timestamp 的方式,可能会由于时间点不统一的缘故造成数据选择或插入失败,通过scn 方式则能够确保记录的约束一致性。获取当前scn 的方式非常多,比如:SQL select current_scn from v$database;SQL select dbms_flashback.get_system_change_number from dual;GET_SYSTEM_CHANGE_NUMBER------------------------ 191460SQL delete tab_test where id5;SQL commit;SQL select * from tab_test as of scn 191460;SQL insert into tab_test select * from tab_test as o

文档评论(0)

1亿VIP精品文档

相关文档