這篇文章主要講解了“Log Miner的知識點有哪些”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Log Miner的知識點有哪些”吧!
目前成都創(chuàng)新互聯(lián)已為上千家的企業(yè)提供了網(wǎng)站建設、域名、虛擬主機、網(wǎng)站托管、服務器托管、企業(yè)網(wǎng)站設計、乾安網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。| Log Miner簡介
Log Miner是Oracle自Oracle 8i以后推出的一個可以分析數(shù)據(jù)庫redo log和archivelog內容的工具,可以通過日志分析所有對數(shù)據(jù)庫的DDL和DML操作,也可以分析出操作的時間與操作時的SCN和進行操作的機器,對于DML操作還可以查詢出還原操作的sql。
| Log Miner組成
源數(shù)據(jù)庫產(chǎn)生LogMiner分析的所有重做日志文件的數(shù)據(jù)庫
挖掘數(shù)據(jù)庫是執(zhí)行LogMiner分析時使用的數(shù)據(jù)庫。
LogMiner數(shù)據(jù)字典是LogMiner使用字典將內部對象標識符和數(shù)據(jù)類型轉換為可讀數(shù)據(jù)。如果沒有字典,Log Miner分析的結果會顯示為二進制數(shù)據(jù)。
| Log Miner數(shù)據(jù)字典選項
當LogMiner分析重做數(shù)據(jù)時,需要一個數(shù)據(jù)字典將日志的對象ID轉換為可讀數(shù)據(jù)。LogMiner提供了三個使用數(shù)據(jù)字典的方式。
1、使用在線目錄( Online Catalog)
使用catalog的數(shù)據(jù)字典,必須在源數(shù)據(jù)庫執(zhí)行。啟動命令為:
SQL> execute dbms_logmnr.start_logmnr (options=>dbms_logmnr.dict_from_online_catalog);
2、將LogMiner字典提取到archive log。啟動命令為:
SQL> execute dbms_logmnr_d.build(options=>dbms_logmnr_d.store_in_redo_logs);
使用這種操作的
3、將LogMiner字典提取到操作系統(tǒng)文件。啟動命令為:
SQL> execute dbms_logmnr_d.build ('directory_name','/xxx/xxx/',dbms_logmnr_d.store_in_flat_file);
使用這種方式的話,需要設置utl_file_dir參數(shù),該參數(shù)需要重啟才能生效。
這個工具使用起來并不復雜。由于將Log Miner數(shù)據(jù)字典提取到操作系統(tǒng)文件在未設置參數(shù)的情況下需要重啟數(shù)據(jù)庫,使用場景比較狹隘,所以以下測試場景為使用Online catalog數(shù)據(jù)字典模式和將字典提取到redo log。
| 測試場景
1、確認數(shù)據(jù)庫開啟了補充日志
sys@RAC11G>select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
SUPPLEME
--------
YES
--如果返回結果為no,通過以下命令開啟
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
注意:在使用Log Miner分析的日志文件之前,必須啟用補充日志。
啟用補充日志時,會在重做日志流中記錄其他信息。如果不開啟,LogMiner的挖掘的一些信息無法正常顯示。
2、創(chuàng)建測試表,并做一些DML與DDL操作
sys@RAC11G> create table test1 (NAME varchar2(20), ID number);
Table created.
sys@RAC11G>insert into test1 values('x','1');
1 row created.
sys@RAC11G>insert into test1 values('xx','2');
1 row created.
sys@RAC11G>insert into test1 values('xxx','3');
1 row created.
sys@RAC11G>commit;
Commit complete.
sys@RAC11G>update test1 set name = 'xxxx' where id =3;
1 row updated.
sys@RAC11G>commit;
Commit complete.
sys@RAC11G>truncate table test1;
Table truncated.
3、切換歸檔日志
sys@RAC11G>alter system switch logfile;
System altered.
sys@RAC11G>alter system switch logfile;
System altered.
--然后查看最后生成的歸檔日志
sys@RAC11G>select * from (select name from v$archived_log where name like '%archive%' order by SEQUENCE# desc ) where rownum <3;
NAME
---------------------------------------------------------------------------------------------------------------------------------------
+DATADG/rac11g/archivelog/2018_10_14/thread_1_seq_293.847.989533723
+DATADG/rac11g/archivelog/2018_10_14/thread_1_seq_292.846.989533631
4、Log Miner添加需要分析的歸檔日志
--添加日志
sys@RAC11G> execute dbms_logmnr.add_logfile(logfilename=>'+DATADG/rac11g/archivelog/2018_10_14/thread_1_seq_293.847.989533723',options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
--添加多個日志,使用DBMS_LOGMNR.ADDFILE選項
sys@RAC11G>execute dbms_logmnr.add_logfile(logfilename=>'+DATADG/rac11g/archivelog/2018_10_14/thread_1_seq_292.846.989533631',options=>DBMS_LOGMNR.ADDFILE);
PL/SQL procedure successfully completed.
5、啟動Log Miner
sys@RAC11G>execute dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);
PL/SQL procedure successfully completed.
6、通過視圖v$logmnr_contents進行分析結果查詢
v$logmnr_contents只有在開啟了Log Miner后才可以進行查詢
select to_char(timestamp,'yyyy-mm-dd hh34:mm:ss'),
operation,
username,
SESSION_INFO,
sql_redo
from v$logmnr_contents
where table_name = 'TEST1';
TO_CHAR(TIMESTAMP,' OPERATION USERNAME SESSION_INFO SQL_REDO
------------------- -------------------------------- --------------- --------------------------------------------------------------------------- ---------------------------------------------------------------------------
2018-10-14 22:10:50 DDL SYS login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS create table test1 (NAME varchar2(20), ID number);
_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@11gnode1 (TNS V
1-V3)
2018-10-14 22:10:29 INSERT SYS login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS insert into "SYS"."TEST1"("NAME","ID") values ('x','1');
_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@11gnode1 (TNS V
1-V3)
2018-10-14 22:10:33 INSERT SYS login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS insert into "SYS"."TEST1"("NAME","ID") values ('xx','2');
_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@11gnode1 (TNS V
1-V3)
2018-10-14 22:10:37 INSERT SYS login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS insert into "SYS"."TEST1"("NAME","ID") values ('xxx','3');
_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@11gnode1 (TNS V
1-V3)
2018-10-14 22:10:51 UPDATE SYS login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS update "SYS"."TEST1" set "NAME" = 'xxxx' where "NAME" = 'xxx' and ROWID = '
_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@11gnode1 (TNS V AAAE6eAABAAAKHBAAC';
1-V3)
2018-10-14 22:10:12 DDL SYS login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS truncate table test1;
_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@11gnode1 (TNS V
1-V3)
.
7、關閉Log Miner
EXECUTE DBMS_LOGMNR.END_LOGMNR();
注意:Log Miner的數(shù)據(jù)只存在PGA中,如果查詢的會話斷開連接,Log Miner也會隨之關閉。
8、將數(shù)據(jù)字典提取到redo log
sys@RAC11G>EXECUTE DBMS_LOGMNR_D.BUILD (OPTIONS => DBMS_LOGMNR_D.STORE_IN_REDO_LOGS);
PL/SQL procedure successfully completed.
根據(jù)字典的大小,它可能包含在多個歸檔文件中。如果已歸檔相關的重做日志文件,則可以找出包含提取的字典的開頭和結尾的歸檔日志??梢圆樵僔$ARCHIVED_LOG視圖
sys@RAC11G>SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN='YES';
NAME
---------------------------------------------------------------------------------------------------------------------------------------
+DATADG/rac11g/archivelog/2018_10_15/thread_1_seq_308.869.989570647
sys@RAC11G>SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_END='YES';
NAME
---------------------------------------------------------------------------------------------------------------------------------------
+DATADG/rac11g/archivelog/2018_10_15/thread_1_seq_309.871.989570649
9、添加包含數(shù)據(jù)字典的歸檔日志以及需要分析的歸檔日志
sys@RAC11G>execute dbms_logmnr.add_logfile(logfilename=>'+DATADG/rac11g/archivelog/2018_10_15/thread_1_seq_308.869.989570647',options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.
sys@RAC11G>execute dbms_logmnr.add_logfile(logfilename=>'+DATADG/rac11g/archivelog/2018_10_15/thread_1_seq_309.871.989570649',options=>dbms_logmnr.addfile);
PL/SQL procedure successfully completed.
sys@RAC11G>execute dbms_logmnr.add_logfile(logfilename=>'+DATADG/rac11g/archivelog/2018_10_14/thread_1_seq_293.847.989533723',options=>dbms_logmnr.addfile);
PL/SQL procedure successfully completed.
sys@RAC11G>execute dbms_logmnr.add_logfile(logfilename=>'+DATADG/rac11g/archivelog/2018_10_14/thread_1_seq_292.846.989533631',options=>dbms_logmnr.addfile);
PL/SQL procedure successfully completed.
10、啟動Log Miner
sys@RAC11G> execute dbms_logmnr.start_logmnr(options=>dbms_logmnr.DICT_FROM_REDO_LOGS);
PL/SQL procedure successfully completed.
11、通過視圖v$logmnr_contents進行分析結果查詢
select to_char(timestamp,'yyyy-mm-dd hh34:mm:ss'),
operation,
username,
SESSION_INFO,
sql_redo
from v$logmnr_contents
7 where table_name = 'TEST1';
TO_CHAR(TIMESTAMP,' OPERATION USERNAME
------------------- -------------------------------- ------------------------------
SESSION_INFO
---------------------------------------------------------------------------------------------------------------------------------------
SQL_REDO
---------------------------------------------------------------------------------------------------------------------------------------
2018-10-14 22:10:50 DDL SYS
login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@
11gnode1 (TNS V1-V3)
create table test1 (NAME varchar2(20), ID number);
2018-10-14 22:10:29 INSERT SYS
login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@
11gnode1 (TNS V1-V3)
insert into "SYS"."TEST1"("COL 1","COL 2") values (HEXTORAW('78'),HEXTORAW('c102'));
2018-10-14 22:10:33 INSERT SYS
login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@
11gnode1 (TNS V1-V3)
insert into "SYS"."TEST1"("COL 1","COL 2") values (HEXTORAW('7878'),HEXTORAW('c103'));
2018-10-14 22:10:37 INSERT SYS
login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@
11gnode1 (TNS V1-V3)
insert into "SYS"."TEST1"("COL 1","COL 2") values (HEXTORAW('787878'),HEXTORAW('c104'));
2018-10-14 22:10:51 UPDATE SYS
login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@
11gnode1 (TNS V1-V3)
update "SYS"."TEST1" set "COL 1" = HEXTORAW('78787878') where "COL 1" = HEXTORAW('787878') and ROWID = 'AAAE6eAABAAAKHBAAC';
2018-10-14 22:10:12 DDL SYS
login_username=SYS client_info= OS_username=oracle Machine_name=11gnode1 OS_terminal=pts/5 OS_process_id=17273 OS_program_name=sqlplus@
11gnode1 (TNS V1-V3)
truncate table test1;
| Log Miner的一些限制
當然,這個工具也有一定的限制
源數(shù)據(jù)庫與挖掘數(shù)據(jù)庫
源數(shù)據(jù)庫和挖掘數(shù)據(jù)庫都必須在同一操作系統(tǒng)平臺上運行。
挖掘數(shù)據(jù)庫可以與源數(shù)據(jù)庫相同或完全獨立。
挖掘數(shù)據(jù)庫必須運行與源數(shù)據(jù)庫相同的版本或更高版本的Oracle數(shù)據(jù)庫軟件。
挖掘數(shù)據(jù)庫必須使用源數(shù)據(jù)庫使用的相同字符集(或字符集的超集)。
Log Miner 數(shù)據(jù)字典
數(shù)據(jù)字典必須由源數(shù)據(jù)庫生成。
歸檔日志
每次分析的所有歸檔日志必須由相同的源數(shù)據(jù)生成。
必須與同一數(shù)據(jù)庫關聯(lián)RESETLOGS SCN。
必須來自8i或更高版本的Oracle數(shù)據(jù)庫。
這些限制都不算苛刻,如果靈活使用這個工具的話,可以使歸檔日志利用大化,在關鍵時間有非常大的作用。
感謝各位的閱讀,以上就是“Log Miner的知識點有哪些”的內容了,經(jīng)過本文的學習后,相信大家對Log Miner的知識點有哪些這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!
當前題目:LogMiner的知識點有哪些-創(chuàng)新互聯(lián)
當前網(wǎng)址:http://www.rwnh.cn/article34/ddcgse.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站改版、響應式網(wǎng)站、網(wǎng)站收錄、云服務器、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容