基於時間戳閃回資料庫
基於時間戳的閃回資料庫更多使用,我在前面的一篇博文中也有所提到,基於時間戳(timestamp)與基於SCN兩種的閃回技術,都可以相互
轉換,轉換函式為:timestamp_to_scn() 與 scn_to_timestamp(),只要便於知道哪一個為先,就用哪一種。
以下讓我們一起進入Scott使用者建立一個實驗表來驗證基於時間戳的閃回資料庫技術:
1、登入Scott使用者:
conn scott/tiger0520
2、建立實驗表,插入資料並查詢:
SQL> create table fbdb_time as select * from fbdb_scn where 1=2;
Table created.
第一條資料
SQL> insert into fbdb_time select 1 as
2 id,dbms_flashback.get_system_change_number as scn,
3 sysdate as dd from dual;
第二條資料
SQL> insert into fbdb_time select 2 as
2 id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
1 row created.
SQL> commit;
Commit complete.
第三條資料
SQL> insert into fbdb_time select 3 as
2 id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
1 row created.
SQL> commit;
Commit complete.
SQL> select * from fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
2 781618 2016-10-02 10:25:24
3 781629 2016-10-02 10:25:45
3、同樣的,刪除使用者Scott模擬損壞資料庫:
SQL> drop user scott cascade;
User dropped.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
4、開啟資料庫到mount狀態,並逐步驗證資料庫的恢復狀況:
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 587205712 bytes
Database Buffers 243269632 bytes
Redo Buffers 2371584 bytes
Database mounted.
SQL>flashback database to timestamp sysdate-15/1440 ;Flashback complete.
SQL> alter database open read only;
此時,檢視資料是否閃回到預期的狀態SQL> select * from fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
此時發現,還沒有完全恢復我們繼續關閉資料庫,再次進行恢復
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 587205712 bytes
Database Buffers 243269632 bytes
Redo Buffers 2371584 bytes
Database mounted.
閃回資料庫到時間點為2016-10-02 10:25:30,開啟到只讀狀態,並查詢資料:
SQL> flashback database to timestamp
2 to_date('2016-10-02 10:25:30','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> alter database open read only;
SQL> select * from fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
2 781618 2016-10-02 10:25:24
這時候,比上一次的閃回,查詢到多了一條資料,這樣算儘量地恢復完整,降低資料的損失率這下,我們就放心再次關閉資料庫,閃回到時間點為2016-10-02 10:25:30時的狀態,並以
alter database open RESETLOGS方式開啟資料庫
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 587205712 bytes
Database Buffers 243269632 bytes
Redo Buffers 2371584 bytes
Database mounted.
SQL> alter database open RESETLOGS;
Database altered.
SQL> select * from scott.fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
2 781618 2016-10-02 10:25:24
這樣,多次驗證在沒有的資料丟失的情況下,我們可以以RESETLOGS方式開啟資料庫。
注意:
基於事件的閃回一般都沒有準確的閃回時間點,那麼就需要我們做到儘量精確,把資料的損失降低到
以 最小,那麼就需要我們多次的重複以 read only 方式開啟資料庫。就像一個形容包子餡兒小的笑話說的
那樣:“吃包子,第一口沒吃到餡兒,第二口,過去了”。我們基於時間的閃回資料庫也是一樣,不要衝動
接 的大約一個時間閃回,閃回完成後就直接 resetlogs 開啟,只要以 resetlogs 開啟後,就不可逆了,
的 作為合格的 DBA ,一定要把損失控制到最小,所以,要多次以 read only 方式 開啟驗證才是上策。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2125842/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【備份恢復】閃回資料庫(三)基於時間戳閃回資料庫資料庫時間戳
- 基於SCN閃回資料庫資料庫
- 閃回(關於閃回資料庫)資料庫
- 【備份恢復】閃回資料庫(二) 基於 SCN 閃回資料庫資料庫
- 資料庫基於版本的閃回資料庫
- 騰訊基於全時態資料庫技術的資料閃回資料庫
- oracle 閃回基於時間的恢復Oracle
- 【備份恢復】閃回資料庫(四)基於可靠還原點閃回資料庫資料庫
- 閃回資料庫時間視窗(flashback database window)資料庫Database
- mysql資料庫時間戳函式MySql資料庫時間戳函式
- 閃回資料庫資料庫
- Oracle資料庫閃回區空間不足Oracle資料庫
- ODI基於源表時間戳欄位獲取增量資料時間戳
- Oracle閃回技術之閃回資料庫Oracle資料庫
- Oracle資料庫閃回Oracle資料庫
- Oracle閃回資料庫Oracle資料庫
- 資料庫的閃回資料庫
- 【備份恢復】閃回資料庫(一)閃回資料庫的管理資料庫
- 閃回資料庫(基礎例項講解)資料庫
- 【備份恢復】閃回資料庫(五)RMAN 命令列閃回資料庫資料庫命令列
- 閃回資料庫的事情資料庫
- Flashback Database 閃回資料庫Database資料庫
- 監視閃回資料庫資料庫
- 實驗-閃回資料庫資料庫
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- Oracle 閃回技術 概覽 資料庫閃回功能Oracle資料庫
- Backup And Recovery User's Guide-使用閃回資料庫-開啟閃回資料庫GUIIDE資料庫
- FlashBack總結之閃回資料庫與閃回刪除資料庫
- [Flashback]開啟資料庫閃回資料庫功能資料庫
- RMAN基於時間點恢復Oracle資料庫Oracle資料庫
- Oracle 閃回資料庫測試Oracle資料庫
- 詳解oracle資料庫閃回Oracle資料庫
- Backup And Recovery User's Guide-使用閃回資料庫來回退資料庫-監控閃回資料庫GUIIDE資料庫
- 閃回資料庫測試之一 :關閉閃回的表空間是否可以開啟資料庫
- 【FLASHBACK】關於閃回資料庫的一點說明資料庫
- Backup And Recovery User's Guide-使用閃回資料庫來回退資料庫-執行閃回資料庫操作GUIIDE資料庫
- 基於時間戳的檔案備份指令碼時間戳指令碼
- Backup And Recovery User's Guide-使用閃回資料庫和還原點-閃回資料庫GUIIDE資料庫