[Flashback]Flashback Database閃回資料庫實驗
Flashback Database閃回資料庫功能極大的降低了由於使用者錯誤導致的資料丟失的恢復成本。這是一種以空間換取縮短恢復時間的解決方案,這是值得的。
1.使用Flashback Database的前提條件
1)啟用了flashback database
2)必須開啟flash recovery area,若為rac,flash recovery area必須位於共享儲存中。
3)必須處於archivelog模式,開啟force logging
2.檢查資料庫是否滿足上述條件
1)驗證是否開啟了flashback功能和force logging
SQL> select flashback_on,force_logging from v$database;
FLASHBACK_ON FOR
------------------ ---
YES YES
如果flashback_on為no狀態,修改方法:http://blog.csdn.net/u011364306/article/details/49249187
如果force_logging為no狀態,修改方法如下:
--這裡已經開啟過,所以重複開啟會報錯
SQL> alter database force logging;
alter database force logging
*
ERROR at line 1:
ORA-12920: database is already in force logging mode
2)驗證是否開啟flash recovery area
SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/oracle/fast_recovery_area
db_recovery_file_dest_size big integer 10G
3)驗證是否開啟歸檔模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 25
Next log sequence to archive 27
Current log sequence 27
3.驗證資料庫可以回滾的最早SCN和TIME
檢視v$flasback_database_log,如果資料庫要恢復的資料比這個時間還早,則閃回無能為力
--時間格式化
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
--透過v$flasback_database_log查詢可以閃回的最早的scn號和時間
SQL> select oldest_flashback_scn,oldest_flashback_time from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI
-------------------- -------------------
1372033 2015-10-19 13:36:13
4.建立測試資料
1)建立測試表test_1,test_2,test_3
SQL> create table test_1 as select * from dba_objects;
Table created.
SQL> create table test_2 as select * from test_1;
Table created.
SQL> create table test_3 as select * from test_1;
Table created.
SQL> select count(*) from test_1;
COUNT(*)
----------
86610
SQL> select count(*) from test_2;
COUNT(*)
----------
86610
SQL> select count(*) from test_3;
COUNT(*)
----------
86610
SQL> set time on
2)將test_2給truncate掉,將test_3給drop掉
14:24:38 SQL> truncate table test_2;
Table truncated.
14:24:57 SQL> drop table test_3;
Table dropped.
3)使用閃回資料庫功能恢復到時間14:24:38
14:25:05 SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
--將資料庫啟動到mount exclusive模式
14:25:42 SQL> startup mount exclusive
ORACLE instance started.
Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 478154296 bytes
Database Buffers 301989888 bytes
Redo Buffers 2596864 bytes
Database mounted.
--閃回資料庫語句
14:26:02 SQL> flashback database to timestamp(to_date('2015-10-19 14:24:38','yyyy-mm-dd hh24:mi:ss'));
Flashback complete.
4)閃回資料庫後有2中方法可以修復資料庫:
使用open read only一般推薦使用該方法,在以只讀模式開啟後,可以將需要恢復的表單獨exp出來,再透過recover database恢復資料庫到原來的狀態,再將缺失的資料篩選重新imp到資料庫中。這樣可以保證對資料庫的影響降到最低,保證對資料庫的其他表沒有影響。
read only開啟後檢視三張表的狀態:
14:27:19 SQL> alter database open read only;
Database altered.
14:27:29 SQL> select count(*) from test_1;
COUNT(*)
----------
86610
14:27:37 SQL> select count(*) from test_2;
COUNT(*)
----------
86610
14:27:39 SQL> select count(*) from test_3;
COUNT(*)
----------
86610
取消閃回的結果,恢復資料庫到原來的狀態
14:28:16 SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
14:28:43 SQL> startup mount
ORACLE instance started.
Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 478154296 bytes
Database Buffers 301989888 bytes
Redo Buffers 2596864 bytes
Database mounted.
--恢復資料庫語句
14:29:05 SQL> recover database;
Media recovery complete.
14:29:10 SQL> alter database open;
Database altered.
14:29:20 SQL> select count(*) from test_1;
COUNT(*)
----------
86610
14:29:30 SQL> select count(*) from test_2;
COUNT(*)
----------
0
14:29:31 SQL> select count(*) from test_3;
select count(*) from test_3
*
ERROR at line 1:
ORA-00942: table or view does not exist
透過上面結果可以檢視資料庫已經恢復到原來的狀態
5)使用open resetlogs,但是透過open resetlogs方式開啟資料庫後,閃回到時間點之後的資料將全部丟失,很多表都會因此受到影響,因此慎重使用
繼續建立test_4表
14:45:40 SQL> create table test_4 as select * from test_1;
Table created.
閃回資料庫
14:46:00 SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
14:46:15 SQL> startup mount exclusive
ORACLE instance started.
Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 478154296 bytes
Database Buffers 301989888 bytes
Redo Buffers 2596864 bytes
Database mounted.
14:46:31 SQL> flashback database to timestamp(to_date('2015-10-19 14:24:38','yyyy-mm-dd hh24:mi:ss'));
Flashback complete.
使用open restlogs開啟資料庫
14:47:28 SQL> alter database open resetlogs;
Database altered.
檢視test_1到test_4表
14:47:51 SQL> select count(*) from test_1;
COUNT(*)
----------
86610
14:48:01 SQL> select count(*) from test_2;
COUNT(*)
----------
86610
14:48:03 SQL> select count(*) from test_3;
COUNT(*)
----------
86610
--發現後來建立的test_4表被丟棄
14:48:05 SQL> select count(*) from test_4;
select count(*) from test_4
*
ERROR at line 1:
ORA-00942: table or view does not exist
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29812844/viewspace-1988812/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Flashback】Flashback Database閃回資料庫功能實驗Database資料庫
- 【Flashback】Flashback Drop閃回刪除功能實驗
- flashback query閃回資料
- ORACLE 閃回檢視v$flashback_database_log/statOracleDatabase
- Oracle 12.2新特性: PDB級閃回資料庫(Flashback PDB)Oracle資料庫
- Flashback Drop閃回刪除功能實踐
- Oracle閃回技術--Flashback Version QueryOracle
- oracle 10g flashback databaseOracle 10gDatabase
- 在Oracle DG Standby庫上啟用flashback database功能OracleDatabase
- flashback實現資料快速復原
- 【FLASHBACK】Oracle閃回及回收站相關語句參考Oracle
- dg_閃回資料庫實驗資料庫
- [20210722]ORA-38760與flashback database.txtDatabase
- 【FLASHBACK】Oracle flashback data archive 介紹OracleHive
- Flashback database必須要有之前的archivelog嗎?DatabaseHive
- GeminiDB Cassandra介面新特性FLASHBACK釋出:任意時間點秒級閃回
- 【Oracle 12c資料庫支援閃回庫功能】實驗Oracle資料庫
- Flashback Query(轉)
- Oracle資料庫閃回Oracle資料庫
- ORACLE Flashback Query偽列Oracle
- 2.6.2 Overview of Flashback PDB in a CDBView
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- Flashback Data Archive原理詳解Hive
- 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匯出
- 騰訊基於全時態資料庫技術的資料閃回資料庫
- database資料庫的資料結構Database資料庫資料結構
- my2sql資料閃回SQL
- ORA-55507: Encountered mining error during Flashback Transaction Backout. functiError
- C++ 未初始化記憶體出現 flashbackC++記憶體