当前位置:软件学习 > Flash >>

关于flashback table的问题

关于flashback table的问题
 
flashback  table 是使用undo tablespace 中的数据来实现 数据的回退的,如果要对表进行flashback ,必须永许表 row movement。否则会出错。
 
下面做个实验验证一下:
先查看scott.dd表是否可以 row movement
[sql] 
SQL> select row_movement from dba_tables where owner='SCOTT' and table_name='DD';  
  
ROW_MOVE  
--------  
DISABLED  
 
我们发现dd表row movement 不可用。在row movement 不可用的情况下,看是否能 flashback table。
[sql] 
SQL> select current_scn from v$database;  
  
CURRENT_SCN  
-----------  
    7514420  
  
SQL> delete from scott.dd;  
  
已删除 1 行。  
  
SQL> commit;  
  
提交完成。  
  
SQL> flashback table scott.dd to scn 7514420;  
flashback table scott.dd to scn 7514420  
                      *  
第 1 行出现错误:  
ORA-08189: 因为未启用行移动功能, 不能闪回表  
  
  
SQL>  
 
经验证:如果要对表进行flashback ,必须永许表 row movement。
让我们重新来一遍:
[sql] 
SQL> select * from scott.dd;  
  
未选定行  
  
SQL> insert into scott.dd values(2);  
  
已创建 1 行。  
  
SQL> /  
  
已创建 1 行。  
  
SQL> /  
  
已创建 1 行。  
  
SQL> /  
  
已创建 1 行。  
 
[sql] 
SQL> select * from scott.dd;  
  
         H  
----------  
         2  
         2  
         2  
         2  
  
SQL>  
 
先将dd表永许 row movement
[sql] 
SQL> alter table scott.dd enable row movement;  
  
表已更改。  
  
SQL> select row_movement from dba_tables where owner='SCOTT' and table_name='DD';  
  
ROW_MOVE  
--------  
ENABLED  
  
SQL>  
重新验证是否可以闪回dd表中的数据:
[sql] 
SQL> select current_scn from v$database;  
  
CURRENT_SCN  
-----------  
    7515150  
  
SQL> delete from scott.dd;  
  
已删除4行。  
  
SQL> commit;  
  
提交完成。  
  
SQL> select * from scott.dd;  
  
未选定行  
  
SQL> flashback table scott.dd to scn 7515150;  
  
闪回完成。  
 
查询dd表中数据:
[sql] 
SQL> select * from scott.dd;  
  
         H  
----------  
         2  
         2  
         2  
         2  
  
SQL>  
 
成功闪回
flashback table 命令支持同时操作多个表,表名以逗号分隔。
由于flashback table是基于undo的表恢复,因此对于truncate操作无法flashback  table。
 
补充:
1:因为flashback table是基于undo进行的回退,因此受undo_retention参数的影响。为了保证能成功回退数据,在undo表空间中,你必须有足够的信息用于回退。
2:语法
[sql] 
FLASHBACK TABLE tablename TO TIMESTAMP to_timestamp('2013-04-24 11:13:48','yyyy-mm-dd hh24:mi:ss');  
FLASHBACK TABLE gdf TO SCN 123456;  
 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,