您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么利用oracle的日志挖掘實現回滾”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么利用oracle的日志挖掘實現回滾”吧!
archery對mysql的支持非常完美,雖然也支持oracle,但是對oracle只支持查詢和執行,不支持備份和審核,還是有很大的遺憾。
現在,我們急需要一個oracle的備份功能,于是我想到了oracle自帶的功能——日志挖掘,它可以實現sql語句的備份功能。
下面是我對日志挖掘的演示。
0、啟動最小日志,這一步是為了日志更加詳細,完整(必須)
alter database add supplemental log data;
1、登錄用戶
SQL> conn czx/xxx; Connected.
2、創建一張測試表
SQL> create table t (id number, name varchar2(10)); Table created.
3、插入一些測試數據
SQL> insert into t values (1,'a'); 1 row created. SQL> insert into t values (2,'b'); 1 row created. SQL> insert into t values (3,'c'); 1 row created. SQL> insert into t values (4,'d'); 1 row created. SQL> insert into t values (5,'e'); 1 row created. SQL> commit; Commit complete. SQL> select * from t; ID NAME ---------- ---------- 1 a 2 b 3 c 4 d 5 e
4、 查看當前會話的sid和serial#
SQL> select s.sid,s.serial# from v$session s where s.sid = (select sid from v$mystat where rownum = 1 ); SID SERIAL# ---------- ---------- 36 3755
5、查看當前數據庫時間,供后面的starttime用
SQL> alter session set nls_date_format='yyyy-mm-dd hh34:mi:ss'; Session altered. SQL> select sysdate from dual; SYSDATE ------------------- 2020-03-15 19:02:53
6、執行一些sql語句,模擬上線sql
SQL> delete from t where id < 3; 2 rows deleted. SQL> update t set name = 'dddd' where id=4; 1 row updated. SQL> insert into t values (6, 'f'); 1 row created. SQL> insert into t values (7, 'g'); 1 row created. SQL> commit; Commit complete. SQL> select * from t; ID NAME ---------- ---------- 3 c 4 dddd 5 e 6 f 7 g
7、再查看一下現在數據庫時間,供后面的endtime用
SQL> select sysdate from dual; SYSDATE ------------------- 2020-03-15 19:08:16
8、通過時間范圍,用在線字典方式將redo日志自動加載到v$logmnr_contents這個視圖中
注意:starttime和endtime就是上面獲得的兩個當前數據庫時間。
SQL> begin dbms_logmnr.start_logmnr( starttime=>to_date('2020-03-15 19:02:53','yyyy-mm-dd hh34:mi:ss'), endtime=>to_date('2020-03-15 19:08:16','yyyy/mm/dd hh34:mi:ss'), options=>dbms_logmnr.dict_from_online_catalog + dbms_logmnr.continuous_mine); end; / PL/SQL procedure successfully completed.
9、 查看v$logmnr_contents視圖的sql_redo和sql_undo內容,就會得到上述執行sql的原始語句和對應的回滾語句
sql> SELECT sql_redo, sql_undo, SESSION#, serial#, username, OS_USERNAME, MACHINE_NAME, SESSION_INFO, operation, xid FROM v$logmnr_contents WHERE SESSION# = ( SELECT s.sid FROM v$session s WHERE s.sid = ( SELECT sid FROM v$mystat WHERE ROWNUM = 1 ) ) AND serial# = ( SELECT serial# FROM v$session s WHERE s.sid = ( SELECT sid FROM v$mystat WHERE ROWNUM = 1 ) ); SESSION# SERIAL# USERNAME OPERATION XID SQL_REDO SQL_UNDO ---------- ---------- ------------------------------ -------------------------------- ---------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- 36 3755 CZX START 0A000900C8060000 set transaction read write; 36 3755 CZX DELETE 0A000900C8060000 delete from "CZX"."T" where "ID" = '1' and "NAME" = 'a' and ROWID = 'AAAVSdAAEAA insert into "CZX"."T"("ID","NAME") values ('1','a'); 36 3755 CZX DELETE 0A000900C8060000 delete from "CZX"."T" where "ID" = '2' and "NAME" = 'b' and ROWID = 'AAAVSdAAEAA insert into "CZX"."T"("ID","NAME") values ('2','b'); 36 3755 CZX UPDATE 0A000900C8060000 update "CZX"."T" set "NAME" = 'dddd' where "ID" = '4' and "NAME" = 'd' and ROWID update "CZX"."T" set "NAME" = 'd' where "ID" = '4' and "NAME" = 'dddd' and ROWID 36 3755 CZX INSERT 0A000900C8060000 insert into "CZX"."T"("ID","NAME") values ('6','f'); delete from "CZX"."T" where "ID" = '6' and "NAME" = 'f' and ROWID = 'AAAVSdAAEAA 36 3755 CZX INSERT 0A000900C8060000 insert into "CZX"."T"("ID","NAME") values ('7','g'); delete from "CZX"."T" where "ID" = '7' and "NAME" = 'g' and ROWID = 'AAAVSdAAEAA 36 3755 CZX COMMIT 0A000900C8060000 commit; 7 rows selected
如果會vue.js和django,就可以把上面這個功能做成web界面形式的。
10、記得最后用完了關閉日志挖掘功能
SQL> begin dbms_logmnr.end_logmnr; end; / PL/SQL procedure successfully completed.
感謝各位的閱讀,以上就是“怎么利用oracle的日志挖掘實現回滾”的內容了,經過本文的學習后,相信大家對怎么利用oracle的日志挖掘實現回滾這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。