最近項目中Oracle庫中一個表log_gpackage有數據丟失現象,但由於沒有啓用歸檔,因此CDC和Dataguard都沒法使用。google一下,最簡單的方法,增長觸發器處理邏輯:sql
1 ---建立觸發器 2 --建立記錄表,該表分別記錄了,刪除的用戶、機器名、ip及刪除時間等 3 create table log_gpackage_history_1120 as 4 (select sid,username,program,machine,'000.000.000.000' ipaddress,sysdate moditime from v$session where 0=1); 5 6 --建立目標表的觸發器,只記錄刪除操做 7 create or replace trigger log_gpackage_history_tr 8 before delete on dbusrdms.log_gpackage 9 for each row 10 begin 11 insert into log_gpackage_history_1120 select sid,username,program,machine,sys_context('userenv','ip_address'),sysdate from v$session 12 where audsid = userenv('sessionid'); 13 end; 14 15 16 --測試數據 17 SELECT * FROM log_gpackage; 18 delete from log_gpackage where LOGSEQNO='172886'; 19 20 21 --檢查測試結果 22 SELECT * FROM log_gpackage_history_1120 23 24 SID USERNAME PROGRAM MACHINE IPADDRESS MODITIME 25 1 484 DBUSRDMS plsqldev.exe WORKGROUP\AP5 192.168.127.8 2018-11-20 23:00:18