Heim  >  Artikel  >  Datenbank  >  Oracle闪回技术flashback

Oracle闪回技术flashback

WBOY
WBOYOriginal
2016-06-07 15:10:171094Durchsuche

一.flashback的功能的开启:select flashback_on from v$database; alter database flashback on; 一定要在归档模式下! 二.flas

一.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
2 as of timestamp sysdate-1/24(一个小时前的数据)
3 where empno=7844;
select empno,sal from scott.emp
2 as of timestamp to_timestamp('2012-07-28 14:00:12','yyyy-mm-dd hh24:mi:ss')(某一时刻的数据)
3 where empno=7844;
select empno,sal from scott.emp
2 as of scn 2642150 (基于scn查询)
3 where empno=7844;
使用闪回查询根据需求来闪回表:
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之间的操作修改
例子:
select versions_xid xid,versions_starttime starttime,versions_endtime endtime,versions_operation operation,sal
2 from scott.emp
3 versions between timestamp minvalue and maxvalue
4 where empno=7844
5 order by starttime;
select versions_xid xid,versions_startscn startscn,versions_endscn endscn,versions_operation operation,sal
2 from scott.emp
3 versions between scn minvalue and maxvalue
4 where empno=7844
5 order by startscn;

五.flashback transaction query
结合闪回版本查询。查看某个对象的事务信息:撤销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>创建一个默认闪回数据归档区:
create flashback archive default arch_default
tablespace arch quota 20M
retenton 1 year;
2>为闪回数据归档区增加一个表空间:
alter flashback archive arch_default
add tablespace mytest
quota 5M;
3>删除闪回数据归档区的表空间:
alter flashback archive arch_default remove tablespace mytest;
4>alter flashback archive arch_default modify retention 1 month;
drop flashback archive arch_default;
********使用闪回数据归档区
1.create table test(n int) flashback archive arch_default ;------创建表时直接使用
2.alter table test flashback archive arch_default;-----表创建后使用
3.插入数据,删除test表的内容
4.select * from test as of timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
********清除闪回数据归档区
1.指定时间前:
alter flashback archive arch_default purge before timestamp to_timestamp('2012-07-28 15:56:05','yyyy-mm-dd hh24:mi:ss');
2.指定scn前
alter flashback archive arch_default purge before 345723;
3.所有
alter flashback archive arch_default purge all

注意:在oracle闪回中常用的命令:
select scn_to_timestamp(2642150) from dual;
select timestamp_to_scn(to_date('2012-07-28 14:26:25','yyyy-mm-dd hh24:mi:ss')) from dual;
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
set time on; 显示时间

本文永久更新链接地址

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn