-------------------------與其餘數據庫相比,Oracle的閃回讓開發者多了一條選擇的路。html
Flashback的目的 sql
Oracle Flashback Technology is a group of Oracle Database features that that let you view past states of database objects or to return database objects to a previous state without using point-in-time media recovery. |
即:Oracle Flashback是一組Oracle數據庫特性,閃回容許你查看過去一個時間數據庫對象的狀態,或者不借助數據庫恢復,就能夠恢復數據庫對象到以前的一個時間狀態。
好比:若是你對數據誤操做,並且已提交,這時想回退該誤操做,將會是很件麻煩的事情。有人可能會說能夠用備份恢復到誤操做以前,但那樣的話,以前所作的其餘正確的操做數據也就一塊兒沒了,而Flashback技術就能夠幫助你快速的恢復誤操做。
須要注意的是Flashback主要是用來解決數據錯誤,或是用戶的一些誤操做,對於介質損壞,任何閃回技術都是無能爲力的,此時咱們只能使用標準的還原、恢復過程。
Flashback技術都包括哪些
- Flashback Query (引入自Oracle 9i)
- Flashback Table (引入自 Oracle 10g)
- Flashback Drop (引入自 Oracle 10g)
- Flashback Version Query (引入自Oracle 10g)
- Flashback Transaction Query (引入自Oracle 10g)
- Flashback Database (引入自Oracle 10g)
- Flashback Data Archive (引入自Oracle 11g)
- Flashback Transaction (引入自Oracle 11g)
閃回技術一般用於快速簡單恢復數據庫中出現的認爲誤操做等邏輯錯誤,從閃回的方式能夠分爲基於數據庫級別閃回、表級別閃回、事務級別閃回。
Flashback Query useful to view the data at a point-in-time in the past. This can be used (only) to view and reconstruct lost data that was deleted or changed by accident.
Flashback Table useful to recover a table to a point-in-time in the past without restoring a backup. Flashback Table is a push button solution to restore the contents of a table to a given point-in-time. An application on top of Flashback Query can achieve this, but with less efficiency.
Flashback Drop provides a way to restore accidentally dropped tables. This will be done with the help of Recyclebin feature.
Flashback Version Query uses undo data stored in the database to view the changes to one or more rows along with all the metadata of the changes.
Flashback Transaction Query useful to examine changes to the database at the transaction level. As a result, we can diagnose problems, perform analysis and audit transactions.
Flashback Database useful to bring database to a prior point in time by undoing all the changes that have taken place since that time. This operation is fast, because we do not need to restore the backups. This in turn results in much less downtime following data corruption or human error. Flashback Database applies to the entire database. It requires configuration and resources, but it provides a fast alternative to performing incomplete database recovery.
Flashback Data Archive - from Oracle 11g, flashback will make use of flashback logs, explicitly created for that table, in FRA (Flash/Fast Recovery Area), will not use undo. Flashback data archives can be defined on any table/tablespace. Flashback data archives are written by a dedicated background process called FBDA so there is less impact on performance. Can be purged at regular intervals automatically.
Flashback技術演進的歷史
Flashback Query
Oracle Flashback Query是指針對特定的表來查詢特定的時間段內的數據變化狀況來肯定是否將表閃回到某一個特定的時刻以保證數據無訛誤存在。這個特性大大的減小了採用時點恢復所需的工做量以及數據庫脫機的時間。
一個列子,DBA誤刪了某業務表,過後忽然意識到了,那麼如何快速的確認&恢復呢
SQL> alter session set nls_date_format='yyyy-mm-dd:hh24:mi:ss';
Session altered
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7369 SMITH CLERK 7902 1980/12/17 800.00 20
7499 ALLEN SALESMAN 7698 1981/2/20 1600.00 300.00 30
7521 WARD SALESMAN 7698 1981/2/22 1250.00 500.00 30
7566 JONES MANAGER 7839 1981/4/2 2975.00 20
7654 MARTIN SALESMAN 7698 1981/9/28 1250.00 1400.00 30
7698 BLAKE MANAGER 7839 1981/5/1 2850.00 30
7782 CLARK MANAGER 7839 1981/6/9 2450.00 10
7788 SCOTT ANALYST 7566 1987/4/19 3000.00 20
7839 KING PRESIDENT 1981/11/17 5000.00 10
7844 TURNER SALESMAN 7698 1981/9/8 1500.00 0.00 30
7876 ADAMS CLERK 7788 1987/5/23 1100.00 20
7900 JAMES CLERK 7698 1981/12/3 950.00 30
7902 FORD ANALYST 7566 1981/12/3 3000.00 20
7934 MILLER CLERK 7782 1982/1/23 1300.00 10
14 rows selected
SQL> create table test1 as (select * from scott.emp);
Table created
SQL> select sysdate from dual;
SYSDATE
-----------
2015/7/19 15:22:17
--這裏DBA誤操做,誤刪除了test1業務表,而且執行了commit
SQL> delete from test1;
14 rows deleted
SQL> commit;
Commit complete
此時test1表中已經沒有數據了
SQL> select * from test1;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
SQL>
但咱們依然能夠經過Flashback Query查詢以前被刪除的數據:
SQL> select * from test1 as of timestamp to_timestamp('2015-07-19:15:22:17','yyyy-mm-dd:hh24:mi:ss');
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7369 SMITH CLERK 7902 1980/12/17 800.00 20
7499 ALLEN SALESMAN 7698 1981/2/20 1600.00 300.00 30
7521 WARD SALESMAN 7698 1981/2/22 1250.00 500.00 30
7566 JONES MANAGER 7839 1981/4/2 2975.00 20
7654 MARTIN SALESMAN 7698 1981/9/28 1250.00 1400.00 30
7698 BLAKE MANAGER 7839 1981/5/1 2850.00 30
7782 CLARK MANAGER 7839 1981/6/9 2450.00 10
7788 SCOTT ANALYST 7566 1987/4/19 3000.00 20
7839 KING PRESIDENT 1981/11/17 5000.00 10
7844 TURNER SALESMAN 7698 1981/9/8 1500.00 0.00 30
7876 ADAMS CLERK 7788 1987/5/23 1100.00 20
7900 JAMES CLERK 7698 1981/12/3 950.00 30
7902 FORD ANALYST 7566 1981/12/3 3000.00 20
7934 MILLER CLERK 7782 1982/1/23 1300.00 10
14 rows selected
SQL>
若是須要,還能夠恢復數據:
SQL> insert into test1 select * from test1 as of timestamp to_timestamp('2015-07-19:15:22:17','yyyy-mm-dd:hh24:mi:ss');
14 rows inserted
SQL> commit;
Flashback Database
Flashback Database,數據庫級別的恢復,能夠將整個數據庫恢復到指定的時間點。
數據庫級別的恢復,你們首先會想到的方式多是藉助備份,沒錯!在10g以前進行全庫恢復只能藉助備份進行(不論是邏輯備份仍是物理備份,反正都得先有備份,才能進行恢復)。那麼10g中推出的Flashback Database特性用來作恢復,相比常規的備份方式有哪些優點呢?主要有兩點:速度和恢復方式。
常規的恢復方式須藉助"備份+歸檔"
當前數據庫SCN爲2000,要將數據庫恢復到2000以前的狀態,如SCN 1850,就必須有在指定時間點前建立的備份。若是沒有適當的備份,咱們想依靠SCN 2000時的歸檔和數據文件,是不可能將數據庫恢復到SCN 1850時的狀態的。
而藉助Flashback Database特性,能夠進行這樣的恢復
從啓用Flashback Database的那刻到當前時間,藉助Flashback Database,咱們能夠將數據庫直接修復到這中間的任意時間點,好比直接將數據庫Flashback至SCN 1850。固然,實際上咱們仍是藉助了備份的,只不過沒有了恢復數據文件的過程,所以纔會表現得如此快速。
操做原理:數據庫不可能無緣無故擁有這樣的功能,Oracle爲了實現Flashback Database特性,另外引入了一組新的日誌文件:Flashback Logs。咱們知道Oracle數據庫中有Online Redologs、Standby Redologs及Archived Redologs,被統稱爲重作日誌,這幾類日誌文件都是用來記錄Oracle數據庫所作的操做,那麼Flashback Logs又是何方高人?起什麼做用?又以什麼形式表現的呢,請聽下回……啊別打別打,俺立刻就說。
其實Flashback Logs並不神祕,與全部的日誌文件功能相同,它也是用來記錄日誌。只不過這個日誌保存的信息比較特別,並不簡單記錄作過什麼的操做,而是記錄下操做執行前要修改的數據,即數據塊的前映像。這些信息被寫入一個專用存儲區叫Flash Recovery Area,簡稱FRA。當須要Flashback Database時,經過Flashback Log中保存的數據,就能夠快速將Oracle數據庫恢復到指定時間點塊的狀態,而後再經過應用重作日誌,將數據庫恢復到一致性狀態。
Flashback Log的建立、刪除、修改都由Oracle自動進行,徹底無須DBA手工干預,惟一須要DBA介入的,就是給Flash Recovery Area分配適當的空間。
參考
《塗抹Oracle》
版權聲明:本文爲博主原創文章,未經博主容許不得轉載。數據庫