Oracle查看表操作歷史記錄並恢復數據


Oracle查看表操作歷史記錄並恢復數據

一、查找表操作記錄

1.首先查找表操作的歷史記錄
select * from v$sqlarea a where a.SQL_TEXT like%表名%;

2.從上面的記錄中找到update語句對應的sql_id
select * from v$sqltext a,v$sqlarea b where a.SQL_ID=b.SQL_ID and b.SQL_ID in(‘cq53826tk4u3c’,‘afftnrfhu5utk’) order by b.LAST_ACTIVE_TIME desc;

3.從上面的記錄中找到最新的sql操作記錄,然后找到用戶名和主機
select * from sys.v_$session l,sys.v_$sql s where s.SQL_ID=‘cq53826tk4u3c’ and l.USERNAME is not null;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

二、恢復數據

//1.根據時間恢復
//示例:
select * from EMP;
delete from EMP where EMPNO=7369;

//查詢當前電腦時間:
select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss’)from dual;

//查詢刪除之前數據:
select * from EMP as of timestamp to_timestamp(2018-04-12 09:12:11,‘yyyy-mm-dd hh24:mi:ss’);
//恢復數據:
flashback table EMP to timestamp to_timestamp(2018-04-12 09:12:11,‘yyyy-mm-dd hh24:mi:ss’);
//注意:若出現報錯:ORA-08189:未啟用行移動功能,不能閃回表;
//則:
alter table EMP enable row movement; //開啟行移動功能
alter table EMP disable row movement; //關閉行移動功能

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
//2.根據數據庫SCN恢復數據
//查詢當前數據庫SCN號:
select current_scn from v$database;(不能執行的話,切換到sys用戶或system用戶查詢)
//查詢到的當前值為:91799986
//縮小SCN號查詢被刪除表數據:(若無數據繼續縮小SCN,由於數據庫操作不止一人,SCN號變化比較多,可以多縮小幾個號)
select * from 表名 as of scn 91799980;
//恢復數據:
flashback table 表名 to scn 91799980;
//恢復完成。若報錯:ORA-08189:未啟用行移動功能,不能閃回表;結果方案同上。

   
   
   
           
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

以上兩種方式,筆者只實踐了第一種,第二種還未實踐。
原地址:https://blog.csdn.net/weixin_39864440/article/details/85261940

https://blog.csdn.net/weixin_40404606/article/details/108164060


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM