Today's experiment is the use of the log mining tool LOGMNR. My test version is 10.2.0.1 by default and does not require additional installation. If you have not installed the package, you can use SYSDBA to log on and run @ $ ORACLE_HOMErdbmsadmindbmslm. SQL in sequence; @ $ ORACLE_HOMErdbmsadmindbmslmd. SQL; first
Today's experiment is the use of the log mining tool LOGMNR. My test version is 10.2.0.1 by default and does not require additional installation. If you have not installed the package, you can use SYSDBA to log on and run the following commands in sequence: @ $ ORACLE_HOME \ rdbms \ admin \ dbmslm. SQL; @ $ ORACLE_HOME \ rdbms \ admin \ dbmslmd. SQL; 1
Today's experiment is the use of the log mining tool LOGMNR. My test version is 10.2.0.1 by default and does not require additional installation. If you have not installed the package, you can use SYSDBA to log on and run the following commands in sequence: @ $ ORACLE_HOME \ rdbms \ admin \ dbmslm. SQL; @ $ ORACLE_HOME \ rdbms \ admin \ dbmslmd. SQL; the first script is used to create the DBMS_LOGMNR package, which is used to analyze log files. The second script is used to create the DBMS_LOGMNR_D package, which is used to create a data dictionary file.
-- Start the experiment
[Oracle @ ora10g ~] $ Sqlplus/as sysdba
SQL * Plus: Release 10.2.0.1.0-Production on 26 09:33:33 2014
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-ProductionWith the Partitioning, OLAP and Data Mining options
SQL> set line 130SQL> select * from v $ log;
GROUP # THREAD # SEQUENCE # bytes members arc status FIRST_CHANGE # FIRST_TIME ------------ ---------- --- hour --------------- ---------- 1 1 8 52428800 1 yes inactive 1402743 3 1 7 52428800 1 yes inactive 1401824
SQL> col member for a45SQL> select group #, member from v $ logfile;
GROUP # MEMBER ---------- runtime 3/u01/app/oracle/oradata/ora10g/redo03.log 2/u01/app/oracle/oradata/ora10g/redo02.log 1/u01/app/oracle/oradata /ora10g/redo01.log
-- Enable log mining
SQL> exec dbms_logmnr.add_logfile ('/u01/app/oracle/oradata/ora10g/redo02.log ');
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.start_logmnr (options => dbms_logmnr.dict_from_online_catalog );
PL/SQL procedure successfully completed.
Let's take a look at the related views used by the LOGMNR tool: SQL> set pages 100SQL> col comments for a40SQL> select * from dict t where t. table_name like '% LOGMNR % ';
TABLE_NAME COMMENTS parameter values $ paisynonym for V _ $ parameters $ LOGMNR_PARAMETERS Synonym for V _ $ parameters $ LOGMNR_DICTIONARY Synonym for V _ $ response $ paisynonym for V _ $ LOGMNR_LOGSV $ paisynonym for V _ $ LOGMNR_STATSV $ prepare Synonym for V _ $ parameters $ prepare Synonym for GV _ $ parameters $ LOGMNR_PARAMETERS Synonym for GV _ $ transactions $ LOGMNR_DICTIONARY Synonym for GV _ $ activities $ prepare Synonym for GV _ $ logs $ LOGMNR_LOGFILE Synonym for V _ $ logs $ LOGMNR_PROCESS Synonym for V _ $ LOGMNR_PROCESSV $ prepare Synonym for V _ $ logs $ LOGMNR_TRANSACTION Synonym for V _ $ response $ LOGMNR_CALLBACK Synonym for V _ $ response $ LOGMNR_SESSION Synonym for V _ $ response $ LOGMNR_LOGFILE Synonym for GV _ $ response $ LOGMNR_PROCESS Synonym for GV _ $ response $ export Synonym for GV _ $ region $ LOGMNR_TRANSACTION Synonym for GV _ $ region $ LOGMNR_REGION Synonym for GV _ $ region $ LOGMNR_CALLBACK Synonym for GV _ $ region $ LOGMNR_SESSION Synonym for GV _ $ LOGMNR_STATSGV $ LOGMNR_DICTIONARY_LOAD Synonym for GV _ $ LOGMNR_DICTIONARY_LOAD
29 rows selected.
Here we mainly use the v $ logmnr_contents view, which stores the content obtained by mining logs. Let's take a look at the table structure:
SQL> desc v $ logmnr_contents; Name Null? Type comment -------- comment scn number cscn number timestamp date comment date thread # NUMBER LOG_ID number xidusn number xidslt number comment number pxidusn number pxidslt number pxidsqn number comment number rbablk number rbabyte number comment 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) TABLE_NAME VARCHAR2 (32) SEG_TYPE NUMBER SEG_TYPE_NAME VARCHAR2 (32) TABLE_SPACE VARCHAR2 (32) ROW_ID VARCHAR2 (18) 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 NUMBER UNDO_VALUE NUMBER SQL _COLUMN_TYPE VARCHAR2 (30) SQL _COLUMN_NAME VARCHAR2 (30) REDO_LENGTH NUMBER REDO_OFFSET NUMBER UNDO_LENGTH NUMBER UNDO_OFFSET NUMBER DATA_OBJV # NUMBER SAFE_RESUME_SCN number xid raw (8) pxid raw (8) AUDIT_SESSIONID NUMBER
-- Obtain the table creation Statement by capturing the keyword "create ".
SQL> select scn, timestamp, log_id, seg_owner, seg_type, table_space, data_blk #, data_obj #, data_objd #, session #, serial #, username, session_info, SQL _redo, SQL _undo 2 from v $ logmnr_contents t 3 where t. SQL _redo like 'create % ';
Scn timestamp LOG_ID when using TABLE_SPACE then # ---------- when ---------- then ---------- DATA_OBJ # When # SESSION # SERIAL # USERNAME ---------- -------- ---------- when SESSION_INFO----------------------------------------------------------------------------------------------------------------------------------SQL_REDO----------------------------------------------------------------------------------------------------------------------------------SQL_UNDO else --- 1404138 2014-12-26 9 ZLM 2 0 53863 0 0
Create table zlm. t1 as select * from dba_objects;
As you can see, the DDL table creation statement has been recorded in the v $ logmnr_contents table.
-- End log mining
SQL> exec dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
Once log mining is completed, you cannot query the v $ logmgr_contents view. An error is returned:
SQL> select scn, timestamp, log_id, seg_owner, seg_type, table_space, data_blk #, data_obj #, data_objd #, session #, serial #, username, session_info, SQL _redo, SQL _undo 2 from v $ logmnr_contents t 3 where t. SQL _redo like 'create % '; from v $ logmnr_contents t * ERROR at line 2: ORA-01306: dbms_logmnr.start_logmnr () must be invoked before selecting from v $ logmnr_contents
In addition, you need to re-specify the log object to be mined; otherwise, an error is still reported:
SQL> exec dbms_logmnr.start_logmnr (options => dbms_logmnr.dict_from_online_catalog); BEGIN dbms_logmnr.start_logmnr (options => BEGIN); END;
[From the Internet (http://www.68idc.cn)] * ERROR at line 1: ORA-01292: no log file has been specified for the current LogMiner sessionORA-06512: at "SYS. DBMS_LOGMNR ", line 58ORA-06512: at line 1
SQL> create table zlm. t2 as select * from zlm. t1; create table zlm. t2 as select * from zlm. t1 * ERROR at line 1: ORA-01652: unable to extend temp segment by 128 in tablespace WEB
The default tablespace WEB space provided by zlm is relatively small and only 10 MB. Therefore, the reported space is insufficient.
SQL> select d. file #, d. ts #, d. bytes/1024/1024 as "Size (M)", t. name from v $ datafile d, v $ tablespace t where d. ts # = t. ts #;
FILE # TS # Size (M) NAME ---------- Listen 1 0 560 SYSTEM 2 1 165 UNDOTBS1 3 2 270 SYSAUX 4 40 USERS 5 6 100 EXAMPLE 6 7 50 ZLM 7 18 20 INDX2 8 19 10 WEB
8 rows selected.
-- Modify zlm's default tablespace to zlm.
SQL> alter user zlm default tablespace zlm;
User altered.
SQL> create table zlm. t2 as select * from zlm. t1;
Table created.
SQL> select * from v $ log;
GROUP # THREAD # SEQUENCE # bytes members arc status FIRST_CHANGE # FIRST_TIME ------------ ---------- --- hour --------------- ---------- 1 1 11 52428800 1 no current 1405472 3 1 10 52428800 1 yes inactive 1405357
The previous operations on table t1 will generate a certain redo and a DDL operation will automatically commit. The current log has been switched to SQL> select scn, timestamp, log_id, seg_owner, seg_type, table_space, data_blk #, data_obj #, data_objd #, session #, serial #, username, session_info, SQL _redo, SQL _undo 2 from v $ logmnr_contents t 3 where t. SQL _redo like 'create % ';
Scn timestamp LOG_ID when using TABLE_SPACE then # ---------- when ---------- then ---------- DATA_OBJ # When # SESSION # SERIAL # USERNAME ---------- -------- ---------- when SESSION_INFO----------------------------------------------------------------------------------------------------------------------------------SQL_REDO----------------------------------------------------------------------------------------------------------------------------------SQL_UNDO else --- 1404138 2014-12-26 9 ZLM 2 0 53863 0 0
Create table zlm. t1 as select * from dba_objects;
Since the current log is a log file of group 1 and the previous mining object is a log file of group 2, we found that 2nd table creation statements were not recorded in the v $ logmgr_contetns view.
-- Remines redo01.log of group 1
SQL> exec dbms_logmnr.add_logfile ('/u01/app/oracle/oradata/ora10g/redo01.log ');
PL/SQL procedure successfully completed.
SQL> exec dbms_logmnr.start_logmnr (options => dbms_logmnr.dict_from_online_catalog );
PL/SQL procedure successfully completed.
-- View the LOGMNR content table
SQL> select scn, timestamp, log_id, seg_owner, seg_type, table_space, data_blk #, data_obj #, data_objd #, session #, serial #, username, session_info, SQL _redo, SQL _undo 2 from v $ logmnr_contents t 3 where t. SQL _redo like 'create % ';
Scn timestamp LOG_ID when using TABLE_SPACE then # ---------- when ---------- then ---------- DATA_OBJ # When # SESSION # SERIAL # USERNAME ---------- -------- ---------- when SESSION_INFO----------------------------------------------------------------------------------------------------------------------------------SQL_REDO----------------------------------------------------------------------------------------------------------------------------------SQL_UNDO else --- 1404138 2014-12-26 9 ZLM 2 0 53863 0 0
Create table zlm. t1 as select * from dba_objects;
1406186 11 ZLM 2 0 53864 0 0 0
Create table zlm. t2 as select * from zlm. t1;
1406401 11 ZLM 2 0 53865 0 0 0
Create table zlm. t2 as select * from zlm. t1;
After redo01.log log mining, the new two statements for creating table t2 are written into v $ logmnr_contents, including the statement that failed to be created due to insufficient space, they both have their own scn numbers and do not conflict with each other. Note: After the logs are mined, use exec dbms_logmnr.end_logmnr to disable it. Otherwise, database resources will be consumed.
Summary:
By using the dbms_logmnr package, you can mine online logs to obtain statements related to database operations, which also plays a role in auditing. There are still many advanced usage methods, including archiving log mining and other content mining. Here we just did a simple test and think this tool is quite useful.