20180520
1.闪回数据库:类似不完全恢复,会丢失闪回点之后的所有操作,并且要使用resetlogs打开数据库,
闪回数据库修复的是逻辑错误,无法修复物理损坏。需要创建闪回日志,运行在归档模式
2.闪回查询:查询过去某个时间的数据库,识别错误操作,受undo保留时间限制
3.闪回事务:执行修复过程,执行sql语句来反转事务中的更改,注意无法回滚提交的更改。
4.闪回表:撤销某一时间点之后的对一张表做的所有操作。
5.闪回表删除:允许将表恢复到删除时的状态,受表空间的可用空间限制。不支持truncate
6.闪回数据归档:能够查看过去任何时间的表的状态。通过fbda进程对dml操作进行捕捉。
启用闪回数据库:
会启用新的进程专门用于写入闪回日志。闪回日志并不是保存所有的修改,因此在闪回数据库时除了应用闪回日志以外还会应用重做日志,保证数据库一致性。
配置参数db_recovery_file_dest,db_recovery_file_dest_size,db_flashback_retention_target(闪回保留时间)
shutdown immediate;
startup mount;
alter database flashback on;
alter database open;
查询是否启用闪回数据库:
select FLASHBACK_ON from v$database;
闪回功能启用后台进程rvwr
相关视图:v$flashback_database_log
使用闪回数据库:as of timestamp|scn
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
create table test1118 as select * from dba_objects;
shutdown immediate;
startup mount;
flashback database to timestamp to_timestamp('2018-01-07 13:14:41','yyyy-mm-dd hh24:mi:ss');
alter database open resetlogs;
闪回被删除的表:
闪回表数据和表上的触发器,权限,索引,除了外键的约束,删除用户将无法闪回该用户下所有删除表,不能找回system表空间中的表
show parameter recyclebin
alter system set recyclebin=on scope=spfile;
create table test tablespace mytbs as select * from user_objects;
drop table test;
show recyclebin查看回收站内容,回收站中空间在需要分配新空间时会被重用
flashback table test to before drop;
flashback table test to befroe drop rename to test1;
闪回查询:依赖undo表空间中的数据
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
删除表中的数据并提交,delete from employees_bak0906;commit;
select * from employees_bak0906 as of timestamp to_timestamp('2018-01-07 13:45:43','yyyy-mm-dd hh24:mi:ss') where employee_id=198;
alter table employees_bak0906 enable row movement;
flashback table employees_bak0906 to timestamp to_timestamp('2018-01-07 13:45:43','yyyy-mm-dd hh24:mi:ss');
alter table employees_bak0906 disable row movement;
闪回版本查询:可以查询多个过去的镜像,未提交数据不被显示
select salary,versions_startscn,versions_endscn,versions_operation from employees_bak0906 versions between scn minvalue and maxvalue where employee_id=198;
闪回事务查询:
相关视图flashback_transaction_query,需要有select any transaction权限,同时启用补充日志
conn / as sysdba
grant select any transaction to hr;
alter database add supplemental log data;
conn hr/hr
update employees_bak set salary=salary+100 where employee_id=198;
commit;
select salary,versions_xid from employees_bak versions between scn minvalue and maxvalue where employee_id=198;
select operation,undo_sql from flashback_transaction_query where xid=hextoraw('0A001F0017030000');
闪回数据归档:可以查询到表更久的过去的状态
创建一个闪回数据归档的专用表空间:create tablespace forarc datafile '/home/oracle/forarc01.dbf' size 100m;
创建归档:create flashback archive default myarc tablespace forarc quota 100m retention 1 year;
这将启用一个后台进程fbda。
alter flashback archive myarc set dafault;
alter flashback archive myarc add tablespace forarc2 quota 100m;
alter flashback archive myarc modify retention 2 year;
alter flashback archive myarc purge before timestamp to_timestamp('','');
alter table hr.employees flashback archive;
相关数据字典:dba_flashback_archive, dba_flashback_archive_ts ,dba_flashback_archive_tables