您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾”吧!
archery對(duì)mysql的支持非常完美,雖然也支持oracle,但是對(duì)oracle只支持查詢和執(zhí)行,不支持備份和審核,還是有很大的遺憾。
現(xiàn)在,我們急需要一個(gè)oracle的備份功能,于是我想到了oracle自帶的功能——日志挖掘,它可以實(shí)現(xiàn)sql語(yǔ)句的備份功能。
下面是我對(duì)日志挖掘的演示。
0、啟動(dòng)最小日志,這一步是為了日志更加詳細(xì),完整(必須)
alter database add supplemental log data;
1、登錄用戶
SQL> conn czx/xxx; Connected.
2、創(chuàng)建一張測(cè)試表
SQL> create table t (id number, name varchar2(10)); Table created.
3、插入一些測(cè)試數(shù)據(jù)
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、 查看當(dāng)前會(huì)話的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、查看當(dāng)前數(shù)據(jù)庫(kù)時(shí)間,供后面的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、執(zhí)行一些sql語(yǔ)句,模擬上線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、再查看一下現(xiàn)在數(shù)據(jù)庫(kù)時(shí)間,供后面的endtime用
SQL> select sysdate from dual; SYSDATE ------------------- 2020-03-15 19:08:16
8、通過時(shí)間范圍,用在線字典方式將redo日志自動(dòng)加載到v$logmnr_contents這個(gè)視圖中
注意:starttime和endtime就是上面獲得的兩個(gè)當(dāng)前數(shù)據(jù)庫(kù)時(shí)間。
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內(nèi)容,就會(huì)得到上述執(zhí)行sql的原始語(yǔ)句和對(duì)應(yīng)的回滾語(yǔ)句
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
如果會(huì)vue.js和django,就可以把上面這個(gè)功能做成web界面形式的。
10、記得最后用完了關(guān)閉日志挖掘功能
SQL> begin dbms_logmnr.end_logmnr; end; / PL/SQL procedure successfully completed.
感謝各位的閱讀,以上就是“怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。