oracle的表和資料恢復
阿新 • • 發佈:2019-02-19
轉自:https://www.cnblogs.com/java-class/p/5817217.html
閱讀目錄
1. 表恢復
對誤刪的表,只要沒有使用 purge 永久刪除選項,那麼基本上是能從 flashback table 區恢復回來的。
資料表和其中的資料都是可以恢復回來的,記得 flashback table 是從 Oralce 10g 提供的,一般步驟有:
a.從 flashback table 裡查詢被刪除的資料表
select * from recyclebin order by droptime desc
b.執行表的恢復
flashback table '需要恢復的表名' to before drop
2. 表資料恢復
對誤刪的表記錄,只要沒有 truncate 語句,就可以根據事務的提交時間進行選擇恢復。
這功能也是 oracle 10g 以上提供的,一般步驟有:
a. 先從 flashback_transaction_query 視圖裡查詢,檢視提供了供查詢用的表名稱、事務提交時間、undo_sql等欄位。
select * from flashback_transaction_query where table_name='需要恢復資料的表名(大寫)';
b.查詢刪除的時間點
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss ') time,
to_char(dbms_flashback.get_system_change_number) scn
from dual;
或者你知道大概記得刪除點,你也可以這樣試試查詢,找出刪除前的時間點
select * from '需要恢復資料的表名' as of timestamp to_timestamp('時間點', 'yyyy-mm-dd hh24:mi:ss');
c.進行資料恢復
通過第二步找到資料丟失的時間點,恢復極為簡單,語句為
flashback table '需要恢復資料的表名' to timestamp to_timestamp('資料丟失的前一時間點',' yyyy-mm-dd hh24:mi:ss');
注意:在執行上述操作的時候,需要允許 oracle 修改分配給行的 rowid,這時候 oracle 需要給恢復的資料分配新的實體地址。
alter table table_name enable row movement;
其實找到資料丟失前的時間點後,恢復資料也可以將需要恢復的資料直接插入到目標表中
insert into '資料丟失的表' select * from t of timestamp to_timestamp('時間點', 'yyyy-mm-dd hh24:mi:ss') where .......;