表誤刪記錄恢複操作,表誤刪記錄

來源:互聯網
上載者:User

表誤刪記錄恢複操作,表誤刪記錄
表誤刪記錄恢複操作

 

 最近處理了個使用者誤刪delete table 的故障,這裡做了一個簡單的匯總,文章內容整理自pub 裡的各位大師的精粹,我這裡偷個懶直接拿來用下。基本處理思路:

1.如果還沒有提交,用rollback。(應該不大可能。)
2.如果提交時間超過5分鐘以上且小於undo_retention的設定,可以使用回閃功能。具體限制和操作可以參考:http://blog.itpub.net/post/468/15464
3.如果上述兩條都不滿足,可以使用logminer從redo中恢複,logminer的使用限制和描述可以參考:http://blog.itpub.net/post/468/13436

這裡有一個使用logminer的簡單的例子:http://blog.itpub.net/post/468/11764
4.如果這個日誌已經重用且沒有啟用歸檔模式,那麼你只能從備份中恢複了

 

 

 

2.使用閃回恢複表資料

2.1----flashback table

主要是是用undo 資料表空間的內容

 

注意:需要啟用表的row movement

 

----格式化時間

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

SQL> select sysdate from dual;

SYSDATE

-------------------

2014-07-27 20:23:37

 

----enable row movement

Alter table xxx enable row movement:

 

----根據scn閃回表:

SQL> flashback table kel.t1 to scn 896744; 

 

---根據時間點閃回表:

SQL> flashback table kel.t1 to timestamp to_timestamp('2014-07-28 00:18:00','yyyy-mm-dd hh24:mi:ss');

 

 

2.2----flashback query:

flashback query只能看到某一個時間點的對象的狀態,而不能看到某個時間段內的狀態變化。

 

select * from tb as of timestamp to_timestamp('2014-07-27 20:23:37','yyyy-mm-dd hh24:mi:ss');

 

 

2.3-----flashback drop

用於恢複使用者誤刪除的對象,包括表、索引等,依賴於tablespace recycle bin,資料表空間資源回收筒

 

初始化參數recyclebin參數用於控制是否啟用recyclebin功能,預設是ON

在recycle bin中,oracle可以區分不同使用者的同名的表。

recycle bin的維護:

 

1、只能用於非系統資料表空間和本地管理的資料表空間

2、如果對象建立在本地管理的資料表空間,而關聯對象,比如索引建立在字典管理的資料表空間上,則恢複時欄位管理的資料表空間關聯對象不能被恢複

3、對象是否能恢複成功,取決於對象空間是否被覆蓋重用

4、不能對recycle bin中的內容進行DML和DDL的操作,只能做查詢操作

5、對象的參考約束不能被恢複,也就是外鍵約束需要重建

 

手動清除recycle bin的空間:

purge tablespace kel

 

 

db_flashback_retention_target Default value        1440 (minutes)

閃回查詢使用的是undo 資訊

 

 

UNDO_RETENTION  理解:

 

 The UNDO_RETENTION parameter is ignored for a fixed size undo tablespace. The database may overwrite unexpired undo information when tablespace space becomes low.

如果undo 資料表空間大小是固定的,則oracle會忽略 undo_retention參數的設定,在undo 空間不足的情況下,oracle可能會覆蓋未到期的undo資訊。

 

 For an undo tablespace with the AUTOEXTEND option enabled, the database attempts to honor the minimum retention period specified by UNDO_RETENTION. When space is low, instead of overwriting unexpired undo information, the tablespace auto-extends. If the MAXSIZE clause is specified for an auto-extending undo tablespace, when the maximum size is reached, the database may begin to overwrite unexpired undo information.

當undo 是自動擴充的,oracle會儘可能的保證 undo_retention設定的undo保留時間;當undo空間不夠使oracle 會優先自動擴充undo 資料表空間,而不是去覆蓋未到期的undo資訊,如果undo tbs 設定了 maxsize  參數,則在達到undo最大空間時,oracle可能就會去覆蓋那些未到期的undo資訊。

 

 

 

注意:對於在system資料表空間的中對象,使用閃回drop無效,因為被drop的對象不會被放在 recyclebin中:

 

----確認是否啟用recyclebin功能

SQL> show parameter recyclebin 

 

----可以通過視圖來進行查看recycle bin中的對象列表:

select object_name as recycle_name,original_name from recyclebin; 

 

----可以像查看普通表一樣,來查看recycle bin中對象的內容:

select count(*) from "BIN$/ti6DA4axIDgQKjAbgFLmA==$0";  

 

要使用flashback drop功能恢複誤刪除的表,需要做以下幾點:

1、確認已刪除的表在recycle bin中

2、使用flashback table來進行恢複

如果同名的表在recycle bin中存在,可以恢複到需要的那個表:

select count(*) from "BIN$/ti6DA4cxIDgQKjAbgFLmA==$0";--查看哪個是想恢複的表  

 

---恢複表

flashback table "BIN$/ti6DA4exIDgQKjAbgFLmA==$0" to before drop;

 

---恢複表並且重新命名為kel1 

flashback table kel to before drop rename to kel1; 

 

 

 

 

 

 

 

3.使用oracle logminer 來進行資料恢複

logmnr其實是非常有用的一個恢複資料的工具,今天有人提到恢複700萬的資料,我也做過幾萬條財務資料的恢複,藉此小結一下。

--建立一個表來儲存提取出來的sql
create table logmnr_content tablespace tools as select scn,cscn,TIMESTAMP,sql_undo from v$logmnr_contents where 1=0;

--通過dba_objects查到表對應的 object_id and data_object_id ,用來在log中提取該表相關的sql_undo
select object_id,data_object_id from dba_objects where object_name = ???

--通過在os中找到的歸檔日誌範圍,進行聯機提取
將undo sql 插入一個表中,比如我的日誌序號範圍是 5813到 5850
為了防止臨時空間不足,一個一個歸檔記錄檔處理。


begin
for i in 8..24 loop

dbms_logmnr.add_logfile(LogFileName=>'/disk2/oradata/arch/crmcn/crmcn_1_'||i||'.arc');
dbms_logmnr.start_logmnr(Options => sys.dbms_logmnr.DICT_FROM_ONLINE_CATALOG);
dbms_logmnr.start_logmnr();

insert into logmnr_content(scn,cscn,TIMESTAMP,sql_undo )
select scn,cscn,TIMESTAMP,sql_undo from v$logmnr_contents
where DATA_OBJD# = 52528;

commit;
dbms_logmnr.end_logmnr();

end loop;
end

/



--將提取出來的sql通過動態sql執行插入表

declare
sql_str varchar2(4000);
begin
for c in (select * from logmnr_content) loop
sql_str := replace(c.sql_undo,';','');
execute immediate sql_str;
end loop;
commit;
end;


注意:如果在這段日誌中還有其他對該表的操作的話,可以結合操作類型 OPERATION和提交scn cscn來判斷到底是不是該恢複的這部分資料。

 

 

 

 

 

 

 

 

 

 

 


誤刪Excel表格內容怎恢複,機器已重啟過

我可以負責任和告訴你,你的表格沒辦法再恢複了
如果檔案刪掉,恢複的方法有多種,但內容刪後再存檔退後,想恢複的幾率幾乎為零
如果你設定了定時儲存的話,你試著到臨時存檔的路徑裡看看有沒有自動存檔的檔案,一般情況每次手工存檔都會覆蓋自動封存的,找找看吧
附片,我的是office2007版的自動封存路徑
記得開啟:顯示系統檔案,顯示隱藏檔案,自動封存是隱藏的
祝你好運~~!



 
oracle 怎恢複誤刪的表記錄資料

--開啟行移動功能
alter table 表名 enable row movement;
--恢複表資料
flashback table 表名 to timestamp to_timestamp('2014-05-19 09:40:00','yyyy-mm-dd hh24:mi:ss');
上述時間為刪除資料的時間
備忘:恢複後請關閉行移動功能
 

相關文章

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.