這篇文章主要講解了“怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾”吧!
成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括沾益網(wǎng)站建設(shè)、沾益網(wǎng)站制作、沾益網(wǎng)頁制作以及沾益網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,沾益網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到沾益省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
archery對MySQL的支持非常完美,雖然也支持oracle,但是對oracle只支持查詢和執(zhí)行,不支持備份和審核,還是有很大的遺憾。
現(xiàn)在,我們急需要一個(gè)oracle的備份功能,于是我想到了oracle自帶的功能——日志挖掘,它可以實(shí)現(xiàn)sql語句的備份功能。
下面是我對日志挖掘的演示。
0、啟動(dòng)最小日志,這一步是為了日志更加詳細(xì),完整(必須)
alter database add supplemental log data;
1、登錄用戶
SQL> conn czx/xxx; Connected.
2、創(chuàng)建一張測試表
SQL> create table t (id number, name varchar2(10)); Table created.
3、插入一些測試數(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ù)庫時(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語句,模擬上線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ù)庫時(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ù)庫時(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īng)的回滾語句
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í)后,相信大家對怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
文章名稱:怎么利用oracle的日志挖掘?qū)崿F(xiàn)回滾
網(wǎng)頁地址:http://www.rwnh.cn/article14/jijpge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、外貿(mào)網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、虛擬主機(jī)、靜態(tài)網(wǎng)站、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)