flashback database 提供了调整闪回功能,依赖flashback log进行不完全恢复。
缺点:
1.不能修复media failure,如数据文件offline,再online的情况。
2.flashback 能恢复到的SCN,取决于flashback log中的记录。
3.如果控制文件为恢复或重建的,则不能使用flashback database
4.如果删除了数据文件或缩小的数据文件,则不能flashback database,需要使用RMAN进行restore,再进行剩下的flshback database 操作。
flashback database 由进程RVWR,flashback log 和 flashback recovery area几部分构成。启用了flashback 特性,则RVWR进程自动启动。
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 85
Next log sequence to archive 87
Current log sequence 87
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------------------------
RESTORE POINT ONLY
联机文档对RESTORE POINT ONLY的解释是:闪回是开启的,但是只能闪回到担保的还原点。
由于担保的还原点的存在,ORACLE还没有立马关闭RVWR进程,此时闪回日志也没有删除,数据库还会继续进行闪回日志的维护,
但是一旦担保的还原点删除,数据库的闪回将会马上关闭,对应的闪回日志也会立马删除。
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 451981312 bytes
Fixed Size 1337100 bytes
Variable Size 352323828 bytes
Database Buffers 92274688 bytes
Redo Buffers 6045696 bytes
Database mounted.
SQL> alter database flashback on;
Database altered.
SQL> alter database open ;
Database altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------------------------
YES
示例
一、备份数据库
[oracle@pc-centos ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jan 15 13:03:07 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1310729769)
RMAN> backup database;
Starting backup at 2014-01-15 13:03:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/jerry.db
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00013 name=/u01/app/oracle/oradata/orcl/backup01.dbf
input datafile file number=00015 name=/u01/app/oracle/oradata/orcl/backup02.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/orcl/rman01.dbf
input datafile file number=00010 name=/u01/app/oracle/oradata/orcl/fbra01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/orcl/testreuse03.dbf
input datafile file number=00014 name=/u01/app/oracle/oradata/orcl/undotbs02.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/orcl/eygle01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/bftbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/orcl/demo01.dbf
channel ORA_DISK_1: starting piece 1 at 2014-01-15 13:03:20
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 01/15/2014 13:09:37
ORA-19502: write error on file "/opt/oracle/obak/bkup_55ou4m4o_1_1", block number 410880 (block size=8192)
ORA-27072: File I/O error
Linux Error: 25: Inappropriate ioctl for device
Additional information: 4
Additional information: 410880
Additional information: 602112
二、检验是否启用归档模式和闪回恢复区以及闪回模式。
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 86
Next log sequence to archive 88
Current log sequence 88
SQL> show parameter db_recovery_file;
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/flash_recovery
_area
db_recovery_file_dest_size big integer 10G
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
三、检查当前SCN和当前时间
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
9673234
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYY-MM-DDHH2
------------------------------
2014-01-20 22:30:34
四、删除表测试
SQL> select * from user01.user01;
ID NAME
---------- --------------------------------------------------------------------------------
1 Jerry1
2 Jerry2
3 Jerry3
4 Jerry4
5 Jerry5
6 Jerry6
7 Jerry7
8 Jerry8
9 Jerry9
10 Jerry10
11 Jerry11
12 Jerry12
13 Jerry13
14 Jerry14
15 Jerry15
16 Jerry16
17 Jerry17
18 Jerry18
19 Jerry19
20 Jerry20
20 rows selected
SQL> drop table user01.user01;
Table dropped
五、重启数据库到mount模式
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 451981312 bytes
Fixed Size 1337100 bytes
Variable Size 331352308 bytes
Database Buffers 113246208 bytes
Redo Buffers 6045696 bytes
Database mounted.
六、执行恢复
1.恢复到当前SCN
SQL> flashback database to scn 9673234;
Flashback complete.
2.恢复到当时时间点
SQL> flashback database to timestamp to_timestamp('2014-01-20 22:30:34','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
七、打开数据库
1.如果使用alter database open resetlogs则从恢复的SCN或者时间点之后的数据会丢失。
2.使用alter database open read only开启数据库,立刻导出误操作表的数据,再recovery database 到闪回之前的状态,再导入误操作表数据。则数据丢失程度最小。
SQL> alter database open resetlogs;
Database altered.
SQL> select * from user01.user01;
ID NAME
---------- --------------------------------------------------------------------------------
1 Jerry1
2 Jerry2
3 Jerry3
4 Jerry4
5 Jerry5
6 Jerry6
7 Jerry7
8 Jerry8
9 Jerry9
10 Jerry10
11 Jerry11
12 Jerry12
13 Jerry13
14 Jerry14
15 Jerry15
16 Jerry16
17 Jerry17
18 Jerry18
19 Jerry19
20 Jerry20
20 rows selected
八、相关视图:
8.1 v$database
用来查看是否启用了闪回
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
8.2v$flashback_database_log
SQL> select * from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIME RETENTION_TARGET FLASHBACK_SIZE ESTIMATED_FLASHBACK_SIZE
-------------------- --------------------- ---------------- -------------- ------------------------
8626249 2013-06-30 21:50:57 1440 3888283648 680632320
OLDEST_FLASHBACK_SCN 可以闪回到的最早SCN
OLDEST_FLASHBACK_TIME 可以闪回到的最早时间点
RETENTION_TARGET 闪回保留策略,单位是分钟
FLASHBACK_SIZE 已经使用的闪回区大小
ESTIMATED_FLASHBACK_SIZE 根据当前策略预估需要的空间大小
8.3 v$flashback_database_stat
SQL> select * from v$flashback_database_stat;
BEGIN_TIME END_TIME FLASHBACK_DATA DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE
----------- ----------- -------------- ---------- ---------- ------------------------
2014-01-20 2014-01-20 205815808 451715072 236544 0
BEGIN_TIME 某个开始时间点
END_TIME 某个结束时间点
FLASHBACK_DATA flashback log 数量
DB_DATA 改变的数据数量
REDO_DATA 日志数量
以上三个单位是字节
阅读(1449) | 评论(0) | 转发(0) |