logmnr 日誌挖掘

安佰勝發表於2010-12-14

做日誌分析(log MNR)
第一步:修改初始引數檔案
修改utl_file_dir路徑
第二步:重新啟動資料庫
第三步:建立目錄檔案
建立目錄dbms_logmnr_d.build
第四步:新增或移動日誌檔案
dbms_logmnr.addfile
第五步:啟動日誌挖掘
dbms_logmnr.start_logmnr
第六步:分析日誌結果查詢
v$logmnr_content--sqlredo/sqlundo兩個內容非常重要

--------

1、連線資料庫
C:\>sqlplus "/ as sysdba"

2、修改引數
SQL> alter system set utl_file_dir='D:\oracle\oradata\log'scope =spfile;
系統已更改。

3、重新啟動資料庫使引數生效
SQL> shutdown immediate
資料庫已經關閉。
已經解除安裝資料庫。
ORACLE 例程已經關閉。
SQL> startup
ORACLE 例程已經啟動。

Total System Global Area  167772160 bytes
Fixed Size                  1247876 bytes
Variable Size              83887484 bytes
Database Buffers           75497472 bytes
Redo Buffers                7139328 bytes
資料庫裝載完畢。
資料庫已經開啟。

4、準備資料
SQL> create table atest as select ts#,name from v$tablespace;
表已建立。

SQL> insert into atest select * from atest;
已建立11行。

SQL> /
已建立22行。

SQL> /
已建立44行。

SQL> commit;
提交完成。

5、檢視當前日誌檔案,切換日誌檔案:
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS              
---------- ---------- ---------- ---------- ---------- --- ----------------    
FIRST_CHANGE# FIRST_TIME                                                       
------------- ----------                                                       
         1          1         20    5242880          1 YES INACTIVE            
       451531 12-12月-07                                                       
                                                                               
         2          1         21    5242880          1 YES INACTIVE            
       460030 12-12月-07                                                       
                                                                               
         3          1         22    5242880          1 NO  CURRENT             
       473938 12-12月-07                                                       

切換日誌檔案:

SQL> alter system switch logfile;
系統已更改。

6、建立目錄檔案
SQL>execute dbms_logmnr_d.build('redo.ora','D:\oracle\oradata\log');
PL/SQL 過程已成功完成


7、加入需要分析的日誌檔案
SQL> execute dbms_logmnr.add_logfile('D:\oracle\oradata\an92\REDO03.LOG',dbms_logmnr.new);
PL/SQL 過程已成功完成。


8、進行日誌分析
SQL> execute dbms_logmnr.start_logmnr(DICTFILENAME=>'D:\oracle\oradata\log\redo.ora');
PL/SQL 過程已成功完成。


9、檢視動態效能檢視v$logmnr_contents
SQL> desc v$logmnr_contents;
 名稱                                      是否為空? 型別
 ----------------------------------------- -------- ----------------------------
 SCN                                                NUMBER
 CSCN                                               NUMBER
 TIMESTAMP                                          DATE
 COMMIT_TIMESTAMP                                   DATE
 THREAD#                                            NUMBER
 LOG_ID                                             NUMBER
 XIDUSN                                             NUMBER
 XIDSLT                                             NUMBER
 XIDSQN                                             NUMBER
 PXIDUSN                                            NUMBER
 PXIDSLT                                            NUMBER
 PXIDSQN                                            NUMBER
 RBASQN                                             NUMBER
 RBABLK                                             NUMBER
 RBABYTE                                            NUMBER
 UBAFIL                                             NUMBER
 UBABLK                                             NUMBER
 UBAREC                                             NUMBER
 UBASQN                                             NUMBER
 ABS_FILE#                                          NUMBER
 REL_FILE#                                          NUMBER
 DATA_BLK#                                          NUMBER
 DATA_OBJ#                                          NUMBER
 DATA_OBJD#                                         NUMBER
 SEG_OWNER                                          VARCHAR2(32)
 SEG_NAME                                           VARCHAR2(256)
 SEG_TYPE                                           NUMBER
 SEG_TYPE_NAME                                      VARCHAR2(32)
 TABLE_SPACE                                        VARCHAR2(32)
 ROW_ID                                             VARCHAR2(19)
 SESSION#                                           NUMBER
 SERIAL#                                            NUMBER
 USERNAME                                           VARCHAR2(30)
 SESSION_INFO                                       VARCHAR2(4000)
 TX_NAME                                            VARCHAR2(256)
 ROLLBACK                                           NUMBER
 OPERATION                                          VARCHAR2(32)
 OPERATION_CODE                                     NUMBER
 SQL_REDO                                           VARCHAR2(4000)
 SQL_UNDO                                           VARCHAR2(4000)
 RS_ID                                              VARCHAR2(32)
 SEQUENCE#                                          NUMBER
 SSN                                                NUMBER
 CSF                                                NUMBER
 INFO                                               VARCHAR2(32)
 STATUS                                             NUMBER
 REDO_VALUE                                         RAW(4)
 UNDO_VALUE                                         RAW(4)
 SQL_COLUMN_TYPE                                    VARCHAR2(32)
 SQL_COLUMN_NAME                                    VARCHAR2(32)
 REDO_LENGTH                                        NUMBER
 REDO_OFFSET                                        NUMBER
 UNDO_LENGTH                                        NUMBER
 UNDO_OFFSET                                        NUMBER


其中:
SESSION_INFO:使用者會話資訊,包括登入使用者名稱,客戶端機器名等。
SQL_REDO:已經處理的SQL語句,不止是使用者發出的,還包括database的處理資訊。
SQL_UNDO:對應SQL_REDO的反操作的SQL語句,如果發現SQL_REDO的操作是錯誤的,可以利用這條語句來恢復。

:DDL 語句是沒有反操作的。


10、檢視日誌分析出的內容

SQL>select SESSION_INFO,SQL_REDO,SQL_UNDO from v$logmnr_contents where username='AN' and operAtION in ('DDL','UPDATE','INSERT','DELETE');

11、停止分析
SQL>execute dbms_logmnr.end_logmnr();
PL/SQL 過程已成功完成。

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

相關文章