闪回
Oracle9i开始提供闪回查询,通过undo实现的,超不好用。
10g厉害的了。很好用的说。
11g增加了闪回的归档。
闪回在归档的模式下才能使用。
查看闪回是否打开
SQL> select flashback_on,name from v$database;
FLASHBACK_ON NAME
------------------ ---------
NO ORADB
SQL> shutdown immediate
SQL> startup mount
SQL> alter database flashback on;
SQL> alter database open;
闪回时间默认 1440 ,也就是1天。
SQL> show parameters flashback ;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440
改改可闪回的时间
SQL> alter system set db_flashback_retention_target=2880
执行数据库闪回,必须是在mount,readonly状态
如果重建了控制文件,则修改控制文件以前的数据是不可以闪回的。
++++表闪回+++++++++++++++++++++
对employee_tab表插入删除一些数据测试
查询某个时间点的数据
select * from employee_tab as of timestamp to_timestamp('2011-05-18 14:10:10','yyyy-mm-dd hh24:mi:ss') --where employee_id='1';
查询所有数据
SELECT VERSIONS_STARTTIME STARTTIME,
VERSIONS_ENDTIME ENDTIME,
VERSIONS_XID,
VERSIONS_OPERATION,
VERSIONS_ENDSCN ENDSCN,
VERSIONS_STARTSCN STARTSCN,
employee_tab.*
FROM employee_tab VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE
返回某个时间点
alter table employee_tab enable row movement;
flashback table employee_tab to timestamp to_timestamp('2011-05-18 14:05:10','yyyy-mm-dd hh24:mi:ss');
删除表
drop table employee_tab ;
闪回
flashback table employee_tab to before drop;
++++数据库闪回++++++
把数据库状态置为mount状态
1 闪回到某时间点
flashback database to timestamp to_timestamp('2011-05-18 14:10:10','yyyy-mm-dd hh24:mi:ss');
2 闪回摸个scn
查日志进程 select first_change# as scn ,thread# as ,sequence# as sequence from v$log ;
flashback database to scn 1017429;
打开数据库
alter database open resetlogs;
随便玩玩
SQL> flashback database to timestamp to_timestamp('2011-05-18 14:05:10','yyyy-mm-dd hh24:mi:ss');
flashback database to timestamp to_timestamp('2011-05-18 14:05:10','yyyy-mm-dd hh24:mi:ss')
*
ERROR at line 1:
ORA-38729: Not enough flashback database log data to do FLASHBACK.
SQL> flashback database to timestamp to_timestamp('2011-05-18 14:10:10','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> flashback database to scn 1017429;
Flashback complete.
SQL> alter database open resetlogs ;
Database altered.