您好,登錄后才能下訂單哦!
這篇文章主要講解了“Log Miner的知識點有哪些”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Log Miner的知識點有哪些”吧!
| Log Miner簡介
Log Miner是Oracle自O(shè)racle 8i以后推出的一個可以分析數(shù)據(jù)庫redo log和archivelog內(nèi)容的工具,可以通過日志分析所有對數(shù)據(jù)庫的DDL和DML操作,也可以分析出操作的時間與操作時的SCN和進(jìn)行操作的機(jī)器,對于DML操作還可以查詢出還原操作的sql。
| Log Miner組成
源數(shù)據(jù)庫產(chǎn)生LogMiner分析的所有重做日志文件的數(shù)據(jù)庫
挖掘數(shù)據(jù)庫是執(zhí)行LogMiner分析時使用的數(shù)據(jù)庫。
LogMiner數(shù)據(jù)字典是LogMiner使用字典將內(nèi)部對象標(biāo)識符和數(shù)據(jù)類型轉(zhuǎn)換為可讀數(shù)據(jù)。如果沒有字典,Log Miner分析的結(jié)果會顯示為二進(jìn)制數(shù)據(jù)。
| Log Miner數(shù)據(jù)字典選項
當(dāng)LogMiner分析重做數(shù)據(jù)時,需要一個數(shù)據(jù)字典將日志的對象ID轉(zhuǎn)換為可讀數(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);
使用這種方式的話,需要設(shè)置utl_file_dir參數(shù),該參數(shù)需要重啟才能生效。
這個工具使用起來并不復(fù)雜。由于將Log Miner數(shù)據(jù)字典提取到操作系統(tǒng)文件在未設(shè)置參數(shù)的情況下需要重啟數(shù)據(jù)庫,使用場景比較狹隘,所以以下測試場景為使用Online catalog數(shù)據(jù)字典模式和將字典提取到redo log。
| 測試場景
1、確認(rèn)數(shù)據(jù)庫開啟了補(bǔ)充日志
sys@RAC11G>select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
SUPPLEME
--------
YES
--如果返回結(jié)果為no,通過以下命令開啟
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
注意:在使用Log Miner分析的日志文件之前,必須啟用補(bǔ)充日志。
啟用補(bǔ)充日志時,會在重做日志流中記錄其他信息。如果不開啟,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進(jìn)行分析結(jié)果查詢
v$logmnr_contents只有在開啟了Log Miner后才可以進(jìn)行查詢
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、關(guān)閉Log Miner
EXECUTE DBMS_LOGMNR.END_LOGMNR();
注意:Log Miner的數(shù)據(jù)只存在PGA中,如果查詢的會話斷開連接,Log Miner也會隨之關(guān)閉。
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ù)字典的大小,它可能包含在多個歸檔文件中。如果已歸檔相關(guān)的重做日志文件,則可以找出包含提取的字典的開頭和結(jié)尾的歸檔日志??梢圆樵僔$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進(jìn)行分析結(jié)果查詢
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的一些限制
當(dāng)然,這個工具也有一定的限制
源數(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ù)庫關(guān)聯(lián)RESETLOGS SCN。
必須來自8i或更高版本的Oracle數(shù)據(jù)庫。
這些限制都不算苛刻,如果靈活使用這個工具的話,可以使歸檔日志利用最大化,在關(guān)鍵時間有非常大的作用。
感謝各位的閱讀,以上就是“Log Miner的知識點有哪些”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Log Miner的知識點有哪些這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。