使用Oracle9i的Flashback Query功能找回誤刪除的資料

來源:互聯網
上載者:User

一個閃回查詢實驗的例子:

資料庫版本:Oracle 9.2.0.4

作業系統:Solaris 8

進行閃回查詢必須設定自動復原段管理,在init.ora設定參數UNDO_MANAGEMENT=AUTO,參數undo_retention=n,決定了能往前閃回的最大時間,值越大就需要越多Undo空間。

# sqlplus wacos/oss

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Jul 22 11:27:19 2005

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL>  select dbms_flashback.get_system_change_number fscn from dual; (查詢當前的SCN號)

      FSCN
----------
 897271357

SQL> select count(*) from customer; (查詢customer表的總大小)

  COUNT(*)
----------
    247064

SQL> select dbms_flashback.get_system_change_number fscn from dual;  (重新查詢當前的SCN號)

      FSCN
----------
 897271368

SQL> delete customer where rownum<100;    (刪除customer表前99行資料)

99 rows deleted.

SQL> commit;

Commit complete.

SQL>  select dbms_flashback.get_system_change_number fscn from dual;  (查詢此時當前的SCN號)

      FSCN
----------
 897271383

SQL> select count(*) from customer;  (此時customer表資料的大小已變化,探索資料少了前99條)

  COUNT(*)
----------
    246965

SQL> create table customer_bak as select * from customer where 1=0;  (建立一個恢複表)

Table created.

SQL> select count(*) from customer_bak;

  COUNT(*)
----------
         0

SQL> select count(*) from customer as of scn 897271357; (選擇SCN向前恢複)

  COUNT(*)
----------
    247064

SQL> select count(*) from customer as of scn 897271368; (嘗試更多的SCN,擷取最佳值)

  COUNT(*)
----------
    247064

選擇恢複到SCN為897271357的時間點:

SQL> insert into customer_bak select * from customer  as of scn 897271357; 

247064 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from customer_bak where rownum <100;

  COUNT(*)
----------
        99

SQL> insert into customer select * from customer_bak where rownum< 100;  (找回前99條記錄,插回原表)

99 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from customer;

  COUNT(*)
----------
    247064

至此,閃回恢複成功完成。

聯繫我們

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