Flashback table复原一个表到某个时间点,或者某个SCN而不用回复数据文件。闪回表依赖UNDO数据,当表结构改变的时候,不能进行闪回。Flashback drop用户恢复被误删除的表。允许你从当前数据库中恢复一个被drop的对象。在执行drop操作时,现在oracle不是真正删除他,而是将对象自动放入回收站,对于一个对象的删除,其实就是一个简单的重命令操作,并且所在的表空间不变。表上面的约束也在放在回收站里面,在闪回后,索引的名称还是系统默认的,需要手工还原。表上的物化视图日志不会随着表的删除而放入回收站。
对闪回表语句不能进行回滚,如何要闪回表,你需要有对表的flashback对象权限或者flashback any table系统权限。row movement对应flash drop没有影响,但是想要使用闪回表来恢复被删除的数据时,就需要开启row movement。flashback drop不会恢复表相关的约束信息
flashback table to scn或者to timestamp,如果当前存在索引,闪回到创建索引之前的时间时候,闪回后,系统仍然存在索引。如果当前drop了索引,那闪回到创建索引的时间点时,索引是变成没有了。
`************************下面测试闪回表*************************
SQL> conn coco/coco;
Connected.
SQL> create table t (a number,b number);
Table created.
SQL> insert into t values(1,1);
1 row created.
SQL> commit;
Commit complete.
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
2171977
SQL> insert into t values(2,2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
A B
---------- ----------
1 1
2 2
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
2172006
----闪回表的时候,需要对表执行row movment
SQL> alter table t enable row movement;
Table altered.
SQL> flashback table t to scn 2171977;
Flashback complete.
SQL> select * from t;------表闪回到具体的SCN时的情形
SQL> select * from t;
A B
---------- ----------
1 1
SQL> flashback table t to scn 2172006;
Flashback complete.
SQL> select * from t; ---闪回到最后的位置
A B
---------- ----------
1 1
2 2`
-------------------下面是验证索引在flashback table to scn中的情况---------------
SQL> drop table t;
Table dropped.
SQL> create table t(a number,b number);
Table created.
SQL> insert into t values(1,1);
1 row created.
SQL> commit;
Commit complete.
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
2188977
SQL> insert into t values(2,2);
1 row created.
SQL> commit;
Commit complete.
SQL> create index idx_t on t(a);
Index created.
SQL> select dbms_flashback.get_system_change_number from dual; ---该时间点表中存在索引
GET_SYSTEM_CHANGE_NUMBER
------------------------
2189035
SQL> insert into t values(3,3);
1 row created.
SQL> commit;
Commit complete.
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
2189068
SQL> select index_name,status from user_indexes where table_name='T';
INDEX_NAME STATUS
------------------------------ --------
IDX_T VALID
SQL> alter table t enable row movement;
Table altered.
SQL> flashback table t to scn 2188977; ----恢复到没有创建索引之前的SCN
Flashback complete.
SQL> select * from t;
A B
---------- ----------
1 1
SQL> select index_name,status from user_indexes where table_name='T';----此时索引仍然存在
INDEX_NAME STATUS
------------------------------ --------
IDX_T VALID
SQL> flashback table t to scn 2189068; ---闪回到最后的SCN
Flashback complete.
SQL> select * from t;
A B
---------- ----------
1 1
2 2
3 3
SQL> drop index idx_t;----删除索引
Index dropped.
SQL> flashback table t to scn 2189035;-----闪回到创建索引的SCN ,但是经过闪回后索引已经不再存在了
Flashback complete.
SQL> select index_name,status from user_indexes where table_name='T';
no rows selected
SQL>
*****************触发器************************
ENABLE | DISABLE TRIGGERS
缺省情况下,闪回表时,表上的triggers是不能使用的,可以使用enable triggers来是闪回的同时启用triggers
TO BEFORE DROP Clause
Using Flashback Drop and Managing the Recycle Bin
When you drop a table, the database does not immediately remove the space associated with the table. The database renames the table and places it and any associated objects in a recycle bin, where, in case the table was dropped in error, it can be recovered at a later time. This feature is called Flashback Drop, and the FLASHBACK TABLE statement is used to restore the table. Before discussing the use of the FLASHBACK TABLE statement for this purpose, it is important to understand how the recycle bin works, and how you manage its contents.
---当你删除一张表,数据库不是立刻删除表所占的空间,数据库会重命名表并把它和相关的对象放在回收站里面,防止表被误删除之后,能够进行恢复,这个特征就叫做闪回删除,使用
flashbackup table继续表的恢复