flashback table快速恢復誤刪除的資料

2021-06-26 21:08:12 字數 1469 閱讀 7822

在oracle資料庫操作中,經常會有不小心誤刪除資料、drop表的情況出現。以前,這種情況發生後,開發人員通常會去求助dba或管理者,使用資料庫備份恢復去找回這些資料。

從oracle 9i、10g開始,你可以不必去用備份來恢復了。有一種快速恢復方法,稱之為flashback。你可以flashback query,也可以flashback table。

一、flashback query

適應範圍:表中的資料持續變化,需要看到某個時間點錯誤刪除修改了某些記錄,可以根據這些記錄再進行資料恢復。

--閃回到15分鐘前

select *  from orders   as of timestamp (systimestamp - interval '15' minute)   where ......

這裡可以使用day、second、month替換minute,例如:

select * from orders as of timestamp(systimestamp - interval '2' day)

--閃回到某個時間點

select  *   from orders   as of timestamp   to_timestamp ('01-sep-04 16:18:57.845993', 'dd-mon-rr hh24:mi:ss.ff') where ...

select *

from t_archive_scan as of timestamp to_timestamp('20141106 11:06:00', 'yyyymmdd hh:mi:ss')

where archive_id = '12010101'

--閃回到兩天前

select * from orders   as of timestamp (sysdate - 2) where.........

二、flashback table

1、表已經drop掉之後使用,可以快速恢復。

flashback table orders to before drop;

如果drop的表已經重新建立了乙個同名稱的表,那麼需要加上rename to子句。

flashback table order to before drop   rename to order_old_version;

2、表的資料錯誤刪除或修改後,沒有後續資料變化,可以快速恢復。

第一步,首先要啟用行遷移

alter table order enable row movement;

第二步,閃回表

到15分鐘前:

flashback table order   to timestamp systimestamp - interval '15' minute;

到某個時間點:

flashback table order to timestamp    to_timestamp('2007-09-12 01:15:25 pm','yyyy-mm-dd hh:mi:ss am')

關於flashback table的問題

關於flashback table的問題 flashback table 是使用undo tablespace 中的資料來實現 資料的回退的,如果要對錶進行flashback 必須永許表 row movement。否則會出錯。下面做個實驗驗證一下 先檢視scott.dd表是否可以 row movem...

flashback table恢復資料

flashback table主要是是用undo 表空間的內容,進行對資料修改的回退操作 語法如下 根據scn號來進行回退 sql flashback table kel.t1 to scn 896744 根據時間來進行回退 sql flashback table kel.t1 to timesta...

分治 快排 快選

快排模板 include using namespace std const int n 1e5 10 int n,a n void quick sort int q,int l,int r quick sort q,l,j quick sort q,j 1,r intmain 快速選擇演算法 選擇...