一.flashback功能的开启:
select flashback_on from v$database;
alter database flashback on;
一定要在归档模式下!
二.flashback table
将表回滚到一个过去的时间点或系统改变号scn上,用于快速恢复表-----依赖于undo表空间
show parameter undo; //查看undo信息
alter system set undo_retention=1200 scope=both;
闪回查询的例子:
SQL> select empno,sal from scott.emp as of timestamp sysdate-1/24 where empno=7844; (一个小时前的数据)
SQL> select empno,sal from scott.emp as of timestamp to_timestamp('2012-07-28 14:00:12','yyyy-mm-dd hh24:mi:ss') where empno=7844; (某一时刻的数据)
SQL> select empno,sal from scott.emp as of scn 2642150 where empno=7844; (基于scn查询)
使用闪回查询根据需求来闪回表:
flashback table test to timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
flashback table test to scn 2649009;
三.flashback drop
结合Oracle的回收站,将删除的对象从回收站中还原-----依赖于oracle回收站
注意:dba删除的对象不会在回收站中!
查看回收站:show recyclebin;
清空回收站:purge dba_recyclebin;
开启回收站功能:alter session set recyclebin=on;
查看回收站: select object_name,original_name,type from user_recyclebin;
在回收站中删除: purge table test1;
闪回删除:flashback table test to before drop;
四.flashback version query
查看某表在指定时间段内或两个scn之间的操作修改
例子:
SQL> select versions_xid xid,versions_starttime starttime,versions_endtime endtime,versions_operation operation,sal from scott.emp versions between timestamp minvalue and maxvalue where empno=7844 order by starttime;
SQL> select versions_xid xid,versions_startscn startscn,versions_endscn endscn,versions_operation operation,sal from scott.emp versions between scn minvalue and maxvalue where empno=7844 order by startscn;
五.flashback transaction query
结合闪回版本查询。查看某个对象的事务信息:撤销sql语句,用于实现对事务进行撤销处理
SQL> select TABLE_NAME,OPERATION,UNDO_SQL from flashback_transaction_query where table_name='emp';
六.flashback database
将数据库回滚到一个过去的时间点或系统改变号上,用于快速恢复数据库------依赖oracle闪回数据恢复区
show parameter db_flash
1. shutdown immediate;
2. startup mount exclusive;
3. flashback database to timestamp(to_date('2012-07-28 17:13:16','yyyy-mm-dd hh24:mi:ss'));
4. alter database open resetlogs;
5. 全备
七.flashback data archive
对对象的修改操作记录在闪回数据归档区域中,这样使数据的闪回不再依赖与undo撤销数据
********管理闪回数据归档区:
1>创建一个默认闪回数据归档区:
SQL> create flashback archive default arch_default tablespace arch quota 20M retenton 1 year;
2>为闪回数据归档区增加一个表空间:
SQL> alter flashback archive arch_default add tablespace mytest quota 5M;
3>删除闪回数据归档区的表空间:
SQL> alter flashback archive arch_default remove tablespace mytest;
SQL> alter flashback archive arch_default modify retention 1 month;
SQL> drop flashback archive arch_default;
********使用闪回数据归档区
1.SQL> create table test(n int) flashback archive arch_default ; ------创建表时直接使用
2.SQL> alter table test flashback archive arch_default; -----表创建后使用
3.插入数据,删除test表的内容
4.SQL> select * from test as of timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
********清除闪回数据归档区
1.指定时间前:
SQL> alter flashback archive arch_default purge before timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
2.指定scn前
SQL> alter flashback archive arch_default purge before 345723;
3.所有
SQL> alter flashback archive arch_default purge all
注意:在oracle闪回中常用的命令:
SQL> select scn_to_timestamp(2642150) from dual;
SQL> select timestamp_to_scn(to_date('2012-07-28 14:26:25','yyyy-mm-dd hh24:mi:ss')) from dual;
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> set time on; 显示时间
select flashback_on from v$database;
alter database flashback on;
一定要在归档模式下!
二.flashback table
将表回滚到一个过去的时间点或系统改变号scn上,用于快速恢复表-----依赖于undo表空间
show parameter undo; //查看undo信息
alter system set undo_retention=1200 scope=both;
闪回查询的例子:
SQL> select empno,sal from scott.emp as of timestamp sysdate-1/24 where empno=7844; (一个小时前的数据)
SQL> select empno,sal from scott.emp as of timestamp to_timestamp('2012-07-28 14:00:12','yyyy-mm-dd hh24:mi:ss') where empno=7844; (某一时刻的数据)
SQL> select empno,sal from scott.emp as of scn 2642150 where empno=7844; (基于scn查询)
使用闪回查询根据需求来闪回表:
flashback table test to timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
flashback table test to scn 2649009;
三.flashback drop
结合Oracle的回收站,将删除的对象从回收站中还原-----依赖于oracle回收站
注意:dba删除的对象不会在回收站中!
查看回收站:show recyclebin;
清空回收站:purge dba_recyclebin;
开启回收站功能:alter session set recyclebin=on;
查看回收站: select object_name,original_name,type from user_recyclebin;
在回收站中删除: purge table test1;
闪回删除:flashback table test to before drop;
四.flashback version query
查看某表在指定时间段内或两个scn之间的操作修改
例子:
SQL> select versions_xid xid,versions_starttime starttime,versions_endtime endtime,versions_operation operation,sal from scott.emp versions between timestamp minvalue and maxvalue where empno=7844 order by starttime;
SQL> select versions_xid xid,versions_startscn startscn,versions_endscn endscn,versions_operation operation,sal from scott.emp versions between scn minvalue and maxvalue where empno=7844 order by startscn;
五.flashback transaction query
结合闪回版本查询。查看某个对象的事务信息:撤销sql语句,用于实现对事务进行撤销处理
SQL> select TABLE_NAME,OPERATION,UNDO_SQL from flashback_transaction_query where table_name='emp';
六.flashback database
将数据库回滚到一个过去的时间点或系统改变号上,用于快速恢复数据库------依赖oracle闪回数据恢复区
show parameter db_flash
1. shutdown immediate;
2. startup mount exclusive;
3. flashback database to timestamp(to_date('2012-07-28 17:13:16','yyyy-mm-dd hh24:mi:ss'));
4. alter database open resetlogs;
5. 全备
七.flashback data archive
对对象的修改操作记录在闪回数据归档区域中,这样使数据的闪回不再依赖与undo撤销数据
********管理闪回数据归档区:
1>创建一个默认闪回数据归档区:
SQL> create flashback archive default arch_default tablespace arch quota 20M retenton 1 year;
2>为闪回数据归档区增加一个表空间:
SQL> alter flashback archive arch_default add tablespace mytest quota 5M;
3>删除闪回数据归档区的表空间:
SQL> alter flashback archive arch_default remove tablespace mytest;
SQL> alter flashback archive arch_default modify retention 1 month;
SQL> drop flashback archive arch_default;
********使用闪回数据归档区
1.SQL> create table test(n int) flashback archive arch_default ; ------创建表时直接使用
2.SQL> alter table test flashback archive arch_default; -----表创建后使用
3.插入数据,删除test表的内容
4.SQL> select * from test as of timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
********清除闪回数据归档区
1.指定时间前:
SQL> alter flashback archive arch_default purge before timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
2.指定scn前
SQL> alter flashback archive arch_default purge before 345723;
3.所有
SQL> alter flashback archive arch_default purge all
注意:在oracle闪回中常用的命令:
SQL> select scn_to_timestamp(2642150) from dual;
SQL> select timestamp_to_scn(to_date('2012-07-28 14:26:25','yyyy-mm-dd hh24:mi:ss')) from dual;
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> set time on; 显示时间
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9034054/viewspace-1986652/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9034054/viewspace-1986652/