- Flashbacking a database means going back to a previous database state.闪回数据库到之前数据库的状态
- The Flashback Database feature provides a way to quickly revert entire Oracle database to the state it was in at a past point in time. 闪回数据库特性提供了一种快速恢复数据库到过去一个时间点的方法 后台进程RVWR把数据块的前映像写入到闪回日志中
- A new background process RVWR introduced which is responsible for writing flashback logs which stores pre-image(s) of data blocks 后台进程RVWR把数据块的前映像写入到闪回日志中
- One can use Flashback Database to back out changes that:
- Have resulted in logical data corruptions.
- Are a result of user error.
- This feature is not applicable for recovering the database in case of media failure. 不适用于介质恢复
配置闪回数据库
Prerequisite
a) Database must be in archivelog mode.
b) Last clean shutdown.
Steps
- 1. Configure the following parameters in parameter file(init.ora) or spfile
参数 | 属性 | 解释 |
---|---|---|
DB_RECOVERY_FILE_DEST | dynamically modifiable | Physical location where RVWR background process writes flashback logs |
DB_RECOVERY_FILE_DEST_SIZE | dynamically modifiable | Maximum size flashback logs can occupy in |
DB_RECOVERY_FILE_DESTDB_FLASHBACK_RETENTION_TARGET | dynamically modifiable | Upper limit in minutes on how far back one can flashback the database |
- Example:
**db_recovery_file_dest参数为0时,不能设定flash_recovery_area参数*
SQL> alter system set db_recovery_file_dest_size=2147483648 scope=spfile;
SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area' scope=spfile;
SQL> alter system set DB_FLASHBACK_RETENTION_TARGET=2880; (2 days) |
- 2. Turn flashback on:
SQL> Startup mount exclusive;
SQL> alter database archivelog;
SQL> Alter database flashback on;
SQL> Alter database open; |
- 3. Check status
SQL> SELECT flashback_on, log_mode FROM gv$database;
SQL> SELECT estimated_flashback_size FROM gv$flashback_database_log;
$ ps -eaf | grep rvwr |
禁用Flashback Database
Alter database flashback on;
Flashback Database Using SQL or RMAN Commands
1.使用SQLPLUS
- Use an SCN or a time stamp in the SQL version
- Example: Flash back the database to a day before using SQL
SQL> shutdown immediate;
SQL> startup mount exclusive;
SQL> flashback database to timestamp(sysdate-1);
SQL> alter database open resetlogs;
2.使用 RMAN
- Using RMAN, you can flash back to a time stamp, SCN, or log sequence number (SEQUENCE) and thread number (THREAD).
- Example:
RMAN> FLASHBACK DATABASE TO TIME = TO_DATE('2002-12-10 16:00:00','YYYY-MM-DD HH24:MI:SS');
RMAN> FLASHBACK DATABASE TO SCN=23565;
RMAN> FLASHBACK DATABASE TO SEQUENCE=223 THREAD=1;
视图
- **V
FLASHBACKDATABASELOG∗∗−monitortheestimatedandactualsizeoftheflashbacklogsintheflashrecovery−Checkflashrecoveryareadiskquota:‘‘‘SQL>selectretentiontarget,flashbacksize,estimatedflashbacksizeFROMV FLASHBACK_DATABASE_LOG;
SQL> SELECT oldest_flashback_scn,oldest_flashback_time FROM V- Determine the current flashback window:
FLASHBACKDATABASELOG;‘‘‘∗∗∗V FLASHBACK_DATABASE_STAT -** monitors the overhead of logging flashback data in the flashback logs. It contains at most 24 rows, with one row for each of the last 24 hours.- The flashback generation for the last hour:
SQL> select to_char(end_time,'yyyy-mm-dd hh:miAM') end_timestamp, flashback_data, db_data, redo_data from v$flashback_database_stat where rownum=1;
从Flashback Database中排除表空间
SQL> ALTER TABLESPACE <ts_name> FLASHBACK {ON|OFF}
SQL> SELECT name, flashback_on 2 FROM v$tablespace;
Note
- Take the tablespace offline before you perform the database flashback operation.
- After performing Flashback Database, drop the tablespace or recover the offline files with traditional point-in-time recovery.
Flash back a RESETLOGS operation
可以闪回到resetlogs之前的一个时间点
SQL> FLASHBACK DATABASE TO BEFORE RESETLOGS;
Limitations
You cannot use Flashback Database in the following situations:
The control file has been restored or re-created.
- A tablespace has been dropped.
- A data file has been shrunk
- 需要开启FRA特性
闪回数据库的一些命令:
**闪回到指定的日期**
FLASHBACK DATABASE TO TIMESTAMP(to_data('2015.07.11 20:03:00','YYYY.MM.DD HH24:MI:SS'));
**闪回到5分钟之前**
FLASHBACK DATABASE TO TIMESTAMP SYSDATE-(1/24/12);
FLASHBACK DATABASE TO BEFORE TIMESTAMP my_date;
**回退到过去的某个SCN点**
FLASHBACK DATABASE TO SCN my_scn;
FLASHBACK DATABASE TO BEFORE SCN my_scn;
**回退到某个Log Sequence号*
flashback database to sequence=223 thread=1;
**回退完成之后以resetlogs的方式打开数据库*
alter database open resetlogs;
**也可以创建一个恢复点*
CREATE RESTORE POINT before_changes;
FLASHBACK DATABASE TO RESTORE POINT before_changes;