SCN(系統(tǒng)改變號(hào)),它的英文全拼為:System Change Number ,它是數(shù)據(jù)庫(kù)中非常重要的一個(gè)數(shù)據(jù)結(jié)構(gòu)。 SCN提供了Oracle的內(nèi)部時(shí)鐘機(jī)制,可被看作邏輯時(shí)鐘,這對(duì)于恢復(fù)操作是至關(guān)重要的 注釋:Oracle 僅根據(jù) SCN 執(zhí)行恢復(fù)。 它定義了數(shù)據(jù)庫(kù)在某個(gè)確切時(shí)刻提交的版本。在事物提交時(shí),它被賦予一個(gè)唯一的標(biāo)示事物的SCN 。一些人認(rèn)為 SCN 是指, System Commit Number ,而通常 SCN 在提交時(shí)才變化,所以很多情況下, 這兩個(gè)名詞經(jīng)常被交替使用。 究竟是哪個(gè)詞其實(shí)對(duì)我們來(lái)說(shuō)并不是最重要的,重要的是我們知道 SCN 是 Oracle 內(nèi)部的時(shí)鐘機(jī)制, Oracle 通過 SCN 來(lái)維護(hù)數(shù)據(jù)庫(kù)的一致性,并通過SCN 實(shí)施 Oracle 至關(guān)重要的恢復(fù)機(jī)制。 具體執(zhí)行流程我們可從以下幾個(gè)示例圖中體會(huì); 1.原表記錄 $ sqlplus eygle/eygle SQL*Plus: Release 10.1.0.2.0 - Production on Wed Mar 30 08:52:04 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production With the Partitioning, OLAP and Data Mining options SQL>select count(*) from t1; COUNT(*) ---------- 9318 2.誤刪除所有記錄 并且提交更改。 SQL>delete from t1; 9318 rows deleted. SQL>commit; Commit complete. SQL>select count(*) from t1; COUNT(*) ---------- 0 3.獲得當(dāng)前SCN 如果能夠確切知道刪除之前SCN最好,如果不知道,可以進(jìn)行閃回查詢嘗試. SQL>select dbms_flashback.get_system_change_number from dual; GET_SYSTEM_CHANGE_NUMBER ------------------------ 10671006 SQL>select count(*) from t1 as of scn 10671000; COUNT(*) ---------- 0 SQL>select count(*) from t1 as of scn 10670000; COUNT(*) ---------- 9318 我們看到在SCN=10670000時(shí),數(shù)據(jù)都在。 4.恢復(fù)數(shù)據(jù). SQL>insert into t1 select * from t1 as of scn 10670000; 9318 rows created. SQL>commit; Commit complete. SQL>select count(*) from t1; COUNT(*) ---------- 9318 文章2 誤刪數(shù)據(jù)后的還原 select timestamp_to_scn(to_timestamp('2009-03-13 09:00:00','YYYY-MM-DD HH:MI:SS')) from dual; 結(jié)果:13526973 將刪除時(shí)間轉(zhuǎn)換為scn select * from reportinfo AS OF SCN 13526973 將reportinfo表中的scn點(diǎn)的數(shù)據(jù)取出 然后可以根據(jù)這個(gè)數(shù)據(jù)進(jìn)行還原操作 create table reporttest as select * from reportinfo where 1=0; insert into reporttest select * from reportinfo AS OF SCN 13526973; --上面兩句應(yīng)該可以合成一句 --create table reporttest as select * from reportinfo AS OF SCN 13526973; 這是reporttest表中就是scn點(diǎn)的reportinfo數(shù)據(jù).處理即可
|