ORACLE flashback

来源:互联网 发布:淘宝做任务赚钱 编辑:程序博客网 时间:2024/05/16 16:11

对象:数据库(用户) 、表、transaction

flashback功能是否开启:select flashback from v$database;

默认关闭的

开启方法:

开启archive log

shutdown immediate

startup mount

alter database archivelog

开启flashback

shutdown immediate;

startup mount;

alter database flashback on;

关闭flashback:flashback log会自动被清除

shutdown immediate;

startup mount;

alter database flashback off;

flashback功能时间:show parameter flashback;

默认时间为1440分钟

回归点:system change number(SCN) / timestamp / restore point

当前timestamp:select timestamp from dual;

当前scn:select current_scn from v$database;

flashback状态:最多可以恢复的时间/scn;flashrecovery_area使用情况

select * from v$flashback_database_log

flashback database:用于还原删除的用户,或者truncated 表

数据库回归条件:

1. 没有删除过tablespace;

2. 没有对表/表空间使用shrink

3. 没有重建过控制文件

4. 如果flashback 回去的点,tablespace状态为offline,flashback命令需要加参数tablespace off

以restore point 回归数据库

1.创建restore point:create restore point abc;

2. 做DML/DLL操作

3. shutdown immediate

4. startup mount;

5. flashback database to restore point abc;

6. alter database open resetlogs;

表回归条件:

1. 不能在system表空间;

2. 不能发生DDL

flashback table

查看是否开启:show parameter recyclebin

查看内容:select * from dba_recyclebin;

使用:

drop table 名称;

flashback table 名 to before drop;

附加:如果表上有Index,会一并回复,但是名称会变成recyclebin编号,需要手工修改

表的主键会自动回复,基于其他表的外键不会自动回复。

手工修改:alter index 名 rename to 名

flashback query

前提条件:

undo_retention:设置的时间长短

guarantee:是否在undo空间不足是仍旧保留

使用:

操作一些DML语句,并且提交

SCN:select * from 表名 as of scn 编号 where 条件

例如:select * from hr.test as of scn 795410 where id=1

timestamp:select * from 表名 as of timestamp to_timestamp('','') where 条件

例如:select * from hr.test as of timestamp to_timestamp('2011-06-29 15:13:00','yyyy-mm-dd hh24:mi:ss') where id =1

flashback DML回退

前提条件:

表空间管理方式是local management(LMT)

表空间分配方式是automatical

开启行移动row movement:alter talbe 名 enable row movement;

使用:

操作一些DML语句,并且提交

SCN: flashback table 名 to scn 编号

例如:flashback table test to scn 795410

timestamp:flashback table 名 to timestamp to_timestamp('','')

例如:flashback table test to timestamp to_timestamp(‘2011-06-29 10:00:00','yyyy-mm-dd hh24:mi:ss');

flashback version

查询时间段内信息:

1. 执行DML:update / delete / insert

2. 查看:

例如:SELECT versions_startscn, versions_starttime,
       versions_endscn, versions_endtime,
       versions_xid, versions_operation,
       name, salary 
  FROM employees
  VERSIONS BETWEEN TIMESTAMP
      TO_TIMESTAMP('2003-07-18 14:00:00', 'YYYY-MM-DD HH24:MI:SS')
  AND TO_TIMESTAMP('2003-07-18 17:00:00', 'YYYY-MM-DD HH24:MI:SS')
  WHERE name = 'JOE';

回退脚本

select * from flashback_transaction_query

可以根据SCN / timestamp / table_name / xid 

错误处理

RMAN执行备份时,报错:ORA-19809: limit exceeded for recovery files

原因:备份区满

解决方法:

1. 修改RMAN备份保留条件,减少备份保存时间;

2. 修改数据库参数,增大DB_RECOVERY_FILE_DEST_SIZE;

针对flash recovery area备份内容:

1. 增量备份;

2. 控制文件的自动备份;

0 0