LogMiner 字典安裝

aishu521發表於2013-03-14

ORA-01371: 未找到完整的LogMiner 字典

需要安裝LogMiner

SQL> @/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/dbmslm.sql

Package created.


Grant succeeded.

SQL> @/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/dbmslmd.sql

Package created.

 

分析

2、把線上重做日誌變成歸檔日誌,這樣分析歸檔日誌就可以了
SQL> alter system switch logfile;
系統已更改。

3、建立日誌分析列表:

----填加要分析的日誌檔案
SQL> execute dbms_logmnr.add_logfile(logfilename=>'D:\oracle\arch\TEST\ARCHIVELOG\2009_08_25\O1_MF_1_32_597FQD7B_.ARC',options=>dbms_logmnr.new);
PL/SQL 過程已成功完成。
---繼續填加,用dbms_logmnr.removefile可以刪除
SQL> execute dbms_logmnr.add_logfile(logfilename=>'D:\oracle\arch\TEST\ARCHIVELOG\2009_08_25\O1_MF_1_30_597B5P7B_.ARC',options=>dbms_logmnr.addfile);
PL/SQL 過程已成功完成。

4、啟動LogMiner
SQL> execute dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);
PL/SQL 過程已成功完成。

5、檢視日誌分析結果:
SQL> col username format a8
SQL> col sql_redo format a50
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
會話已更改。

SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents where seg_name='DEPT';
USERNAME        SCN TIMESTAMP           SQL_REDO
-------- ---------- ------------------- -----------------------------------
            1645927 2009-08-25 16:54:56 delete from "SCOTT"."DEPT" where "DEPTNO" = '40' and "DNAME" = 'OPERATIONS' and "LOC" = 'BOSTON' and "PHONE" IS NULL and "ADDRESS" IS       NULL and ROWID = 'AAAMfNAAEAAAAAQAAD';
SYS         1645931 2009-08-25 16:54:57 alter table scott.dept add(phone varchar2(32)) ;
SYS         1645992 2009-08-25 16:56:33 alter table scott.dept add(address varchar2(300)) ;

6、結束LogMiner
SQL> execute dbms_logmnr.end_logmnr;
PL/SQL 過程已成功完成。

---------------------------------------------------------------------------------

用摘取LogMiner字典到字典檔案分析DDL操作:

1、進行DDL操作,以便分析
SQL> conn scott/admin
已連線。
SQL> drop table emp;
表已刪除。
SQL> drop table dept;
表已刪除。
SQL> conn /as sysdba
已連線。
SQL> alter system switch logfile;
系統已更改。

2、使用字典檔案,請檢視資料庫是否配置utl_file_dir,這個引數為字典檔案的目錄。配置該引數後,需要重啟資料庫
SQL> show user;
USER 為 "SYS"
SQL> show parameter utl;
NAME                                 TYPE        VALUE                         
------------------------------------ ----------- ------------
create_stored_outlines               string                                    
utl_file_dir                         string                          
SQL> alter system set utl_file_dir='D:\oracle\logminer' scope=spfile;
System altered.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
SQL> show parameter utl
NAME                                 TYPE        VALUE                         
------------------------------------ ----------- -----------
create_stored_outlines               string                                    
utl_file_dir                         string      D:\oracle\logminer     

3、建立字典檔案:
SQL> execute dbms_logmnr_d.build ('dict.ora','D:\oracle\logminer',dbms_logmnr_d.store_in_flat_file);
PL/SQL 過程已成功完成。

4、建立日誌分析列表:
SQL> execute dbms_logmnr.add_logfile(logfilename=>'D:\oracle\arch\TEST\ARCHIVELOG\2009_08_25\O1_MF_1_32_597FQD7B_.ARC',options=>dbms_logmnr.new);
PL/SQL 過程已成功完成。

SQL> execute dbms_logmnr.add_logfile(logfilename=>'D:\oracle\arch\TEST\ARCHIVELOG\2009_08_25\O1_MF_1_30_597B5P7B_.ARC',options=>dbms_logmnr.addfile);
PL/SQL 過程已成功完成。

5、啟動LogMiner
SQL> execute dbms_logmnr.start_logmnr(dictfilename=>'D:\oracle\logminer\dict.ora',options=>dbms_logmnr.ddl_dict_tracking);
PL/SQL 過程已成功完成。

6、查詢分析日誌結果:

SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents  where lower(sql_redo) like '%table%';
USERNAME        SCN TIMESTAMP      SQL_REDO
-------- ---------- -------------- -----------------------------------
            1647538 25-8月 -09     ALTER TABLE "SCOTT"."EMP" RENAME CONSTRAINT "PK_EMP" TO "BIN$f/mFjN+nTmaYjrb17YU80w==$0" ;
            1647550 25-8月 -09     ALTER TABLE "SCOTT"."EMP" RENAME TO "BIN$E5UujHaTR+uItpLtzN0Ddw==$0" ;
            1647553 25-8月 -09     drop table emp AS "BIN$E5UujHaTR+uItpLtzN0Ddw==$0" ;
            1647565 25-8月 -09     ALTER TABLE "SCOTT"."DEPT" RENAME CONSTRAINT "PK_DEPT" TO "BIN$3imFL+/1SqONFCB7LoPcCg==$0" ;
            1647571 25-8月 -09     ALTER TABLE "SCOTT"."DEPT" RENAME TO "BIN$kYKBLvltRb+vYaT6RkaRiA==$0";
            1647574 25-8月 -09     drop table dept AS "BIN$kYKBLvltRb+vYaT6RkaRiA==$0" ;                        
                                             
或者其他的查詢:

SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents where username='SYS';
USERNAME TIMESTAMP           SQL_REDO                                          
-------- ------------------- --------------------------------------------------
USERNAME        SCN TIMESTAMP      SQL_REDO
-------- ---------- -------------- -----------------------------------
SYS         1647487 25-8月 -09     set transaction read write;
SYS         1647488 25-8月 -09     alter user scott account unlock;
SYS         1647490 25-8月 -09     Unsupported
SYS         1647492 25-8月 -09     commit;
                         
7、結束LogMiner
SQL> execute dbms_logmnr.end_logmnr;
PL/SQL 過程已成功完成。

注意,v$logmnr_contents內容儲存了日誌的內容,只在當前會話有效,如果想長期儲存分析,可以在當前會話用create table tablename as select * from v$logmnr_contents語句來持久儲存。


其他操作:


1.生成資料字典檔案
SQL> show parameter utl_file_dir
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir                         string      *
SQL> EXECUTE dbms_logmnr_d.build(dictionary_filename => 'dict20090625.dat',dictionary_location => '/orabak');
PL/SQL procedure successfully completed.

2.可以先設定使用的表空間
SQL> EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('erp') 
PL/SQL procedure successfully completed.

3.開始分析日誌
SQL> execute dbms_logmnr.start_logmnr(dictfilename=>'/orabak/dict20090625.dat');
PL/SQL procedure successfully completed.

提取特定時間的日誌:
dbms_logmnr.start_logmnr(dictfilename=>'/orabak/dict20090625.dat',
starttime=>to_date('2009-06-24 09:30:00','YYYY-MM-DD HH24:MI:SS'),
endtime=>to_date('2009-06-24 12:00:59','YYYY-MM-DD HH24:MI:SS'))

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15187685/viewspace-756188/,如需轉載,請註明出處,否則將追究法律責任。

相關文章