關於flashback table

flashback  table 是使用undo tablespace 中的數據來實現 數據的回退的,如果要對錶進行flashback ,必須永許表 row movement。否則會出錯。

下面做個實驗驗證一下:

先查看scott.dd表是否可以 row movement

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> 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> select * from scott.dd;

未選定行

SQL> insert into scott.dd values(2);

已創建 1 行。

SQL> /

已創建 1 行。

SQL> /

已創建 1 行。

SQL> /

已創建 1 行。

SQL> select * from scott.dd;

         H
----------
         2
         2
         2
         2

SQL>

先將dd表永許 row movement

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> 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> 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:語法

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;





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章