【Flashback】Flashback Database閃回資料庫功能實踐
Flashback Database閃回資料庫功能極大的降低了由於使用者錯誤導致的資料丟失的恢復成本。這是一種以空間換取縮短恢復時間的解決方案,這是值得的。
這裡給出閃回資料庫的使用方法,體驗一下這種恢復操作的便利性。
1.使用Flashback Database的前提條件
1)啟用了flashback database
2)必須開啟flash recovery area,若為RAC,flash recovery area必須位於共享儲存中。
3)必須處於archivelog模式,開啟FORCE LOGGIN
2.一一確認上面的前提條件是否滿足
1)驗證是否啟用了flashback database並確認FORCE LOGGIN是否開啟
SYS@ora11g> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
------------------ ---
YES NO
若flashback_on為“NO”,修改方法見《【Flashback】啟用Flashback Database閃回資料庫功能》(http://space.itpub.net/519536/viewspace-590636)
若force_logging為“NO”,請使如下SQL語句開啟。
SYS@ora11g> alter database force logging;
Database altered.
SYS@ora11g> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
------------------ ---
YES YES
2)驗證是否開啟flash recovery area
此步驟在啟用閃回資料庫功能時已經確認過。
SYS@ora11g> 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 3852M
3)資料庫是否處於archivelog模式
SYS@ora11g> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 11
Next log sequence to archive 13
Current log sequence 13
3.確認資料庫可以前滾到的SCN和Time的方法
如果需要恢復的資料點比這個時間還要早的話,很不幸,閃回資料庫功能將無能為力。
SYS@ora11g> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SYS@ora11g> select oldest_flashback_scn,oldest_flashback_time from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI
-------------------- -------------------
1033529 2012-04-02 03:36:40
4.閃回資料庫功能閃亮登場
1)建立測試表fd_1、fd_2和fd_3
SYS@ora11g> create table fd_1 as select * from dba_objects;
Table created.
SYS@ora11g> create table fd_2 as select * from fd_1;
Table created.
SYS@ora11g> create table fd_3 as select * from fd_1;
Table created.
SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_3;
COUNT(*)
----------
72465
SYS@ora11g> set time on
21:59:40 SYS@ora11g> select sysdate from dual;
SYSDATE
-------------------
2012-04-07 21:59:44
2)truncate表fd_2、drop掉表fd_3
21:59:44 SYS@ora11g> truncate table fd_2;
Table truncated.
22:00:06 SYS@ora11g> drop table fd_3;
Table dropped.
3)使用Flashback Database功能進行恢復到刪除前的時間點2012-04-07 21:59:44
22:00:17 SYS@ora11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
22:02:04 SYS@ora11g> startup mount exclusive;
ORACLE instance started.
Total System Global Area 313860096 bytes
Fixed Size 1336232 bytes
Variable Size 247467096 bytes
Database Buffers 58720256 bytes
Redo Buffers 6336512 bytes
Database mounted.
22:02:52 SYS@ora11g> Flashback Database to timestamp(to_date('2012-04-07 21:59:44','yyyy-mm-dd hh24:mi:ss'));
Flashback complete.
4)閃回後修復資料庫兩種方式之一:open read only
推薦使用這樣的方法進行恢復,因為在read only方式開啟之後,將需要恢復的表EXP匯出,然後透過recover database將資料庫恢復到原狀態,再將缺失的資料IMP到資料庫中。這樣操作對資料庫的影響可以降低到最小,可以保證其他表沒有資料的丟失。
read only開啟後檢視三張表的狀態:
22:03:57 SYS@ora11g> alter database open read only;
Database altered.
22:04:33 SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
22:04:37 SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
72465
22:04:40 SYS@ora11g> select count(*) from fd_3;
COUNT(*)
----------
72465
取消閃回結果,恢復到閃回前狀態的方法:
22:04:43 SYS@ora11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
22:05:09 SYS@ora11g> startup mount;
ORACLE instance started.
Total System Global Area 313860096 bytes
Fixed Size 1336232 bytes
Variable Size 247467096 bytes
Database Buffers 58720256 bytes
Redo Buffers 6336512 bytes
Database mounted.
22:06:08 SYS@ora11g> recover database;
Media recovery complete.
22:06:18 SYS@ora11g> alter database open;
Database altered.
22:06:41 SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
22:06:55 SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
0
22:06:59 SYS@ora11g> select count(*) from fd_3;
select count(*) from fd_3
*
ERROR at line 1:
ORA-00942: table or view does not exist
可見,透過上面的recover後,資料庫恢復到了閃回前的狀態。
5)閃回後修復資料庫兩種方式之二:open resetlogs
透過open resetlogs方式開啟資料庫後,很顯然,閃回到時間點之後的資料將全部丟失,慎用!
SYS@ora11g> alter database open resetlogs;
SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_3;
COUNT(*)
----------
72465
5.小結
這裡對Flashback Database閃回資料庫的語法進行總結。閃回資料庫可以在SQL*Plus環境和RMAN環境下使用。
基於時間戳進行閃回資料庫操作方法:
Flashback Database to timestamp(to_date('2012-04-07 21:59:44','yyyy-mm-dd hh24:mi:ss'));
Flashback Database to timestamp(sysdate-1/24);
基於SCN進行閃回資料庫操作方法:
Flashback Database to 1321427;
Good luck.
secooler
12.04.07
-- The End --
這裡給出閃回資料庫的使用方法,體驗一下這種恢復操作的便利性。
1.使用Flashback Database的前提條件
1)啟用了flashback database
2)必須開啟flash recovery area,若為RAC,flash recovery area必須位於共享儲存中。
3)必須處於archivelog模式,開啟FORCE LOGGIN
2.一一確認上面的前提條件是否滿足
1)驗證是否啟用了flashback database並確認FORCE LOGGIN是否開啟
SYS@ora11g> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
------------------ ---
YES NO
若flashback_on為“NO”,修改方法見《【Flashback】啟用Flashback Database閃回資料庫功能》(http://space.itpub.net/519536/viewspace-590636)
若force_logging為“NO”,請使如下SQL語句開啟。
SYS@ora11g> alter database force logging;
Database altered.
SYS@ora11g> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
------------------ ---
YES YES
2)驗證是否開啟flash recovery area
此步驟在啟用閃回資料庫功能時已經確認過。
SYS@ora11g> 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 3852M
3)資料庫是否處於archivelog模式
SYS@ora11g> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 11
Next log sequence to archive 13
Current log sequence 13
3.確認資料庫可以前滾到的SCN和Time的方法
如果需要恢復的資料點比這個時間還要早的話,很不幸,閃回資料庫功能將無能為力。
SYS@ora11g> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SYS@ora11g> select oldest_flashback_scn,oldest_flashback_time from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI
-------------------- -------------------
1033529 2012-04-02 03:36:40
4.閃回資料庫功能閃亮登場
1)建立測試表fd_1、fd_2和fd_3
SYS@ora11g> create table fd_1 as select * from dba_objects;
Table created.
SYS@ora11g> create table fd_2 as select * from fd_1;
Table created.
SYS@ora11g> create table fd_3 as select * from fd_1;
Table created.
SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_3;
COUNT(*)
----------
72465
SYS@ora11g> set time on
21:59:40 SYS@ora11g> select sysdate from dual;
SYSDATE
-------------------
2012-04-07 21:59:44
2)truncate表fd_2、drop掉表fd_3
21:59:44 SYS@ora11g> truncate table fd_2;
Table truncated.
22:00:06 SYS@ora11g> drop table fd_3;
Table dropped.
3)使用Flashback Database功能進行恢復到刪除前的時間點2012-04-07 21:59:44
22:00:17 SYS@ora11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
22:02:04 SYS@ora11g> startup mount exclusive;
ORACLE instance started.
Total System Global Area 313860096 bytes
Fixed Size 1336232 bytes
Variable Size 247467096 bytes
Database Buffers 58720256 bytes
Redo Buffers 6336512 bytes
Database mounted.
22:02:52 SYS@ora11g> Flashback Database to timestamp(to_date('2012-04-07 21:59:44','yyyy-mm-dd hh24:mi:ss'));
Flashback complete.
4)閃回後修復資料庫兩種方式之一:open read only
推薦使用這樣的方法進行恢復,因為在read only方式開啟之後,將需要恢復的表EXP匯出,然後透過recover database將資料庫恢復到原狀態,再將缺失的資料IMP到資料庫中。這樣操作對資料庫的影響可以降低到最小,可以保證其他表沒有資料的丟失。
read only開啟後檢視三張表的狀態:
22:03:57 SYS@ora11g> alter database open read only;
Database altered.
22:04:33 SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
22:04:37 SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
72465
22:04:40 SYS@ora11g> select count(*) from fd_3;
COUNT(*)
----------
72465
取消閃回結果,恢復到閃回前狀態的方法:
22:04:43 SYS@ora11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
22:05:09 SYS@ora11g> startup mount;
ORACLE instance started.
Total System Global Area 313860096 bytes
Fixed Size 1336232 bytes
Variable Size 247467096 bytes
Database Buffers 58720256 bytes
Redo Buffers 6336512 bytes
Database mounted.
22:06:08 SYS@ora11g> recover database;
Media recovery complete.
22:06:18 SYS@ora11g> alter database open;
Database altered.
22:06:41 SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
22:06:55 SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
0
22:06:59 SYS@ora11g> select count(*) from fd_3;
select count(*) from fd_3
*
ERROR at line 1:
ORA-00942: table or view does not exist
可見,透過上面的recover後,資料庫恢復到了閃回前的狀態。
5)閃回後修復資料庫兩種方式之二:open resetlogs
透過open resetlogs方式開啟資料庫後,很顯然,閃回到時間點之後的資料將全部丟失,慎用!
SYS@ora11g> alter database open resetlogs;
SYS@ora11g> select count(*) from fd_1;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_2;
COUNT(*)
----------
72465
SYS@ora11g> select count(*) from fd_3;
COUNT(*)
----------
72465
5.小結
這裡對Flashback Database閃回資料庫的語法進行總結。閃回資料庫可以在SQL*Plus環境和RMAN環境下使用。
基於時間戳進行閃回資料庫操作方法:
Flashback Database to timestamp(to_date('2012-04-07 21:59:44','yyyy-mm-dd hh24:mi:ss'));
Flashback Database to timestamp(sysdate-1/24);
基於SCN進行閃回資料庫操作方法:
Flashback Database to 1321427;
Good luck.
secooler
12.04.07
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-590661/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Flashback】Flashback Database閃回資料庫功能實驗Database資料庫
- 【Flashback】Flashback Drop閃回刪除功能實驗
- Flashback Drop閃回刪除功能實踐
- flashback query閃回資料
- ORACLE 閃回檢視v$flashback_database_log/statOracleDatabase
- Oracle 12.2新特性: PDB級閃回資料庫(Flashback PDB)Oracle資料庫
- 在Oracle DG Standby庫上啟用flashback database功能OracleDatabase
- Oracle閃回技術--Flashback Version QueryOracle
- oracle 10g flashback databaseOracle 10gDatabase
- flashback實現資料快速復原
- 【FLASHBACK】Oracle閃回及回收站相關語句參考Oracle
- [20210722]ORA-38760與flashback database.txtDatabase
- 【FLASHBACK】Oracle flashback data archive 介紹OracleHive
- Flashback database必須要有之前的archivelog嗎?DatabaseHive
- GeminiDB Cassandra介面新特性FLASHBACK釋出:任意時間點秒級閃回
- 【Oracle 12c資料庫支援閃回庫功能】實驗Oracle資料庫
- Flashback Query(轉)
- dg_閃回資料庫實驗資料庫
- Oracle資料庫閃回Oracle資料庫
- ORACLE Flashback Query偽列Oracle
- 2.6.2 Overview of Flashback PDB in a CDBView
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- Flashback Data Archive原理詳解Hive
- Orcale利用閃回功能恢復資料
- Oracle 閃回資料庫測試Oracle資料庫
- 詳解oracle資料庫閃回Oracle資料庫
- Oracle 備份恢復之 FlashbackOracle
- guarantee restore points-Flashback after RMAN restoreREST
- [20181002]DBMS_FLASHBACK與函式.txt函式
- 用flashback恢復儲存過程儲存過程
- [20180424]開啟表空flashback on.txt
- Oracle資料庫閃回區空間不足Oracle資料庫
- 刪使用者刪表空間的操作還能flashback回來嗎?
- [20180724]Flashback query和子游標共享.txt
- 基於flashback_scn的expdp匯出
- Oracle閃回功能恢復偶然丟失的資料(轉)Oracle
- 如何運維多叢集資料庫?58 同城 NebulaGraph Database 運維實踐運維資料庫Database
- 騰訊基於全時態資料庫技術的資料閃回資料庫
- database資料庫的資料結構Database資料庫資料結構