Oracle中Drop,Delete,Truancate表恢複

來源:互聯網
上載者:User

標籤:oracle   drop   delete   

Oracle中Drop,delete,truancate表恢複

oracle中,常常會由於一些失誤導致表的刪除,以下是我寫的一些表恢複的方法。

閃回模式得滿足條件(啟用閃回區和啟用歸檔):

1.檢查是否啟動了flash recovery area

show parameter db_recovery_file

2.檢查是否啟用了歸檔

archive log list;


(一)Drop表的恢複

如果按照平時刪除表的方法:(Drop table tablename;)的話。表不會立即被刪除,而是存放於資源回收筒中(Oracle 10g以後才有)。我們可以通過閃回(Flashback)把表恢複。

 查看被資源回收筒中刪除的表:

    Select * from dba_recyclebin (where type=‘TABLE‘); --找出對應的表是否存在

  閃回表:

    Flashback tbale 表名 to before drop;

**資源回收筒存放的不僅僅只有表,還有其他對象


(二)Delete表的恢複

同樣,Delete後可以通過閃回時間戳記或者閃回SCN號進行恢複。

  基於時間戳記恢複

①確定刪除資料的時間(在刪除資料之前的時間就行,不過最好是刪除資料的時間點)

②用以下語句找出刪除的資料:

 select * from 表名 as of timestamp to_timestamp(‘刪除時間點‘,‘yyyy-mm-dd hh24:mi:ss‘)

③開啟行移動功能 

 alter table 表名 enable row movement

④把刪除的資料重新插入原表:

 insert into 表名 (select * from 表名 as of timestamp to_timestamp(‘刪除時間點‘,‘yyyy-mm-dd hh24:mi:ss‘));注意要保證主鍵不重複。

⑤關閉行移動功能 ( 千萬別忘記 )

 alter table 表名 disable row movement

  基於SCN號恢複

①擷取當前的SCN號
 select dbms_flashback.get_system_change_number from dual; --假設得到scn號為10672000

②如果知道刪除前的SCN號最好,如果不知道就通過閃回查詢嘗試.

 select count(*) from 表名 as of scn 10671000; --如果資料量為0,則繼續提前scn號

 select count(*) from 表名 as of scn 10670000; --查詢的資料量為原來的資料量,則ok

③通過查詢的SCN號進行閃回恢複

 insert into 表名 select * from tablename as of scn 10670000;


(三)Truncate表的恢複

truncate表後不會產生日誌記錄和復原段空間的使用,不能用查詢閃回恢複。

①最簡單的方法:下載使用PRM (資料庫災難恢複工具)

②進行資料庫閃回(在生產庫不推薦):

 select  sysdate from dual;  --查看時間戳記,確認已經開啟閃回,如果沒開啟,只能用①方法了;

 shutdown immediate;  --關閉資料庫

 startup mount;  --啟動到mount狀態

 flashback database to timestamp to_timestamp(‘2017-07-30 18:22:33‘,‘yyyy-mm-dd hh24:mi:ss‘);  --閃回刪除時間點的時間

 alter database open;  --開啟資料庫









Oracle中Drop,Delete,Truancate表恢複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.