Oracle 表和表資料恢複

來源:互聯網
上載者:User

標籤:sa

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 .......;


Oracle 表和表資料恢複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.