- 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;
視圖
- **VFLASHBACKDATABASELOG???monitortheestimatedandactualsizeoftheflashbacklogsintheflashrecovery?Checkflashrecoveryareadiskquota:‘‘‘SQL>selectretentiontarget,flashbacksize,estimatedflashbacksizeFROMVFLASHBACK_DATABASE_LOG;
- Determine the current flashback window:
- 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;
來自為知筆記(Wiz)