Professional Documents
Culture Documents
Carl Dudley
Staffordshire University, UK
Carl Dudley - 1
Oracle8i LogMiner
Carl Dudley - 2
The LogMiner Environment
Online Log
Files
Data
Dictionary Archive
Log Files
LogMiner
Dictionary
File
~~~~~~~~~~~
~~~~~~~~~~~
~~~~~~~~~~~
~~~~~~~~~~~ Fixed (v$) View
~~~~~~~~~~~
Carl Dudley - 3
Redo Log Analysis
Carl Dudley - 4
The LogMiner Dictionary
Carl Dudley - 5
Building the LogMiner Dictionary
EXECUTE dbms_logmnr_d.build
(dictionary_filename => orcldict.ora
,dictionary_location => c:\lmnr);
Carl Dudley - 6
The Log of the Dictionary Creation
SQL> execute dbms_logmnr_d.build('test_dictionary7.ora','c:\rmanback');
LogMnr Dictionary Procedure started
LogMnr Dictionary File Opened
TABLE: OBJ$ recorded in LogMnr Dictionary File
TABLE: TAB$ recorded in LogMnr Dictionary File
TABLE: COL$ recorded in LogMnr Dictionary File
TABLE: SEG$ recorded in LogMnr Dictionary File
TABLE: UNDO$ recorded in LogMnr Dictionary File
TABLE: UGROUP$ recorded in LogMnr Dictionary File
TABLE: TS$ recorded in LogMnr Dictionary File
TABLE: CLU$ recorded in LogMnr Dictionary File
TABLE: IND$ recorded in LogMnr Dictionary File
TABLE: ICOL$ recorded in LogMnr Dictionary File
TABLE: LOB$ recorded in LogMnr Dictionary File
TABLE: USER$ recorded in LogMnr Dictionary File
TABLE: FILE$ recorded in LogMnr Dictionary File
TABLE: PARTOBJ$ recorded in LogMnr Dictionary File
TABLE: PARTCOL$ recorded in LogMnr Dictionary File
TABLE: TABPART$ recorded in LogMnr Dictionary File
TABLE: INDPART$ recorded in LogMnr Dictionary File
TABLE: SUBPARTCOL$ recorded in LogMnr Dictionary File
TABLE: TABSUBPART$ recorded in LogMnr Dictionary File
TABLE: INDSUBPART$ recorded in LogMnr Dictionary File
TABLE: TABCOMPART$ recorded in LogMnr Dictionary File
TABLE: INDCOMPART$ recorded in LogMnr Dictionary File
Procedure executed successfully - LogMnr Dictionary Created
Carl Dudley - 7
The Need for the Dictionary File
Carl Dudley - 8
Contents of the Dictionary File
Carl Dudley - 9
The dbms_logmnr Package
Created by dbmslogmnr.sql
(dbmslm.sql/prvtlm.plb on 8.1.6)
Carl Dudley - 10
Examining the Redo Log Files
The LogMiner must first be given a list of log files to analyze
EXECUTE dbms_logmnr.add_logfile
(Options => dbms_logmnr.NEW
,logfilename => log1orcl.ora);
This action clears any existing list of logs to be analyzed and
starts a new list, with log1orcl.ora as first in the list
EXECUTE dbms_logmnr.add_logfile
(Options => dbms_logmnr.ADDFILE
,logfilename => log2orcl.ora);
This action adds log2orcl.ora to the list of logs to be analyzed
EXECUTE dbms_logmnr.add_logfile
(Options => dbms_logmnr.REMOVEFILE
,logfilename => log1orcl.ora);
Carl Dudley - 11
Examining the Redo Log Files (2)
EXECUTE dbms_logmnr.add_logfile
(Options => dbms_logmnr.NEW
,logfilename => log1orcl.ora);
EXECUTE dbms_logmnr.add_logfile
(Options => dbms_logmnr.ADDFILE
,logfilename => log2orcl.ora);
EXECUTE dbms_logmnr.add_logfile
(Options => dbms_logmnr.ADDFILE
,logfilename => log3orcl.ora);
Carl Dudley - 12
Automatic Log List Generation (1)
Carl Dudley - 13
Automatic Log List Generation (2)
BEGIN
file_out := UTL_FILE.FOPEN(log_dir,log_list,'w');
FOR log_rec IN log_cur LOOP
IF counter = 1 THEN
file_buff := 'DBMS_LOGMNR.ADD_LOGFILE
('''||LOG_REC.NAME||''',DBMS_LOGMNR.NEW);';
ELSE
file_buff := 'DBMS_LOGMNR.ADD_LOGFILE
('''||LOG_REC.NAME||''',DBMS_LOGMNR.ADDFILE);';
END IF;
UTL_FILE.PUT_LINE(file_out,'BEGIN');
UTL_FILE.PUT_LINE(file_out,file_buff);
UTL_FILE.PUT_LINE(file_out,'END;');
UTL_FILE.PUT_LINE(file_out,'/');
counter := counter + 1;
END LOOP;
UTL_FILE.FCLOSE(file_out);
END;
Carl Dudley - 14
Automatic Log List Generation (3)
Contents of listlogs.sql
BEGIN
DBMS_LOGMNR.ADD_LOGFILE('D:\ORACLE\ORADATA\ORAC\ARCHIVE\ORACT001S00192.ARC
,DBMS_LOGMNR.NEW);
END;
/
BEGIN
DBMS_LOGMNR.ADD_LOGFILE('D:\ORACLE\ORADATA\ORAC\ARCHIVE\ORACT001S00193.ARC
,DBMS_LOGMNR.ADDFILE);
END;
/
...
Carl Dudley - 15
Starting the Logminer
EXECUTE dbms_logmnr.start_logmnr
(Dictfilename => orcldict.ora
,StartTime => 01-dec-1999 09:00:00
,EndTime => 01-dec-1999 09:30:00);
Carl Dudley - 16
Viewing LogMiner Information
A simple example
SQL_REDO
--------
delete from EMP where EMPNO = 7777 and ROWID = `AAACOOAEBAADPCACA';
SQL_UNDO
--------
insert into EMP(EMPNO, SAL) values (7777,1500)
Without a dictionary file, you can expect to see this kind of output
Carl Dudley - 17
Viewing Logminer Information
SELECT username
,scn
,TO_CHAR(timestamp
,'dd-mon-yyyy hh24:mi:ss') time
,sql_redo
,sql_undo
FROM v$logmnr_contents
WHERE username = 'FRED'
AND TO_CHAR(timestamp
,'dd-mon-yyyy hh24:mi:ss')
BETWEEN 01-DEC-1999 09:02:00'
AND 01-DEC-1999 09:04:00';
Carl Dudley - 18
Limitations/Features of the Logminer (1)
SQL_UNDO
---------------------------------
Unsupported (Chained Row)
Log Miner generates low-level SQL, not what was actually issued
Cannot fully trace an application
-- If an update statement updates three rows, three separate
row-level update statements are shown in SQL_UNDO column
3 rows updated.
SQL_UNDO
------------------------------------------------------------
update EMP set SAL = 2450 where rowid = `AAACOOAEBAADPCACI';
update EMP set SAL = 1300 where rowid = `AAACOOAEBAADPCACN';
update EMP set SAL = 5000 where rowid = `AAACOOAEBAADPCACG';
Carl Dudley - 19
Limitations/Features of the Logminer (2)
Carl Dudley - 20
Limitations/Features of the LogMiner (3)
Carl Dudley - 21
Analysing Oracle 8.0 Logfiles
Logminer can build a dictionary file from an Oracle 8.0 database using
dbms_logmnr_d.build
Carl Dudley - 22
Calculating Table Access Statistics
Start LogMiner to determine activity during a two week period in August
EXECUTE dbms_logmnr.start_logmnr(
StartTime => `07-Aug-99, EndTime => `15-Aug-99'
,DictFileName => `/usr/local/dict.ora');
Carl Dudley - 23
The Logminer Views
v$logmnr_dictionary
Information on dictionary file in use
v$logmnr_logs
Information on log files under analysis
Log sequence numbers for each log
-- If the log files do not have consecutive sequence
numbers, an entry is generated signifying a gap
High and low SCNs, high and low times of all currently
registered logs
v$logmnr_parameters
Current LogMiner session parameters
High and low SCNs, high and low times, info, status
v$logmnr_contents
Results of analysis
Contains masses of information ( > 50 columns! )
Carl Dudley - 24
Columns in v$logmnr_contents
operation
Shows type of SQL operation
-- INSERT, UPDATE, DELETE, COMMIT, BEGIN_TRANSACTION
-- All other operations are reported as UNSUPPORTED or
INTERNAL_OPERATION
seg_type_name
Only tables are supported in the first release
rollback
1 represents a rollback operation otherwise 0
row_id
Only The ROWID of the affected row
Carl Dudley - 25
Tracking Changes made by a Transaction
Typical scenario - you have found an anomaly in a column
Carl Dudley - 26
Tracking Changes to Specific Columns(1)
LogMiner can be used to monitor changes on specific columns
Need to create a file called logmnr.opt
MUST be held in the same directory as the dictionary file
EXECUTE dbms_logmnr.start_logmnr(
,DictFileName => `/usr/local/dict.ora
,Options => dbms_logmnr.USE_COLMAP);
Carl Dudley - 27
Tracking Changes to Specific Columns(2)
logmnr.opt has a very rigid format
Each entry has to be syntactically and lexically correct
colmap = SCOTT EMP (1, ENAME);
Carl Dudley - 28
Tracking Changes to a Schema
Scripts can be written to generate entries for logmnr.opt
Carl Dudley - 29
Schema Changes - Package Body (1)
CREATE OR REPLACE PACKAGE BODY filesave AS
FUNCTION logmnr( directory VARCHAR2,
schemaname VARCHAR2,
filename VARCHAR2 DEFAULT 'logmnr.opt')
RETURN INTEGER IS
CURSOR curtab IS
SELECT object_name table_name
FROM dba_objects
WHERE owner=UPPER(schemaname) AND object_type='TABLE'
ORDER BY object_id ASC;
t_tab curtab%ROWTYPE;
CURSOR curcol (v_schemaname VARCHAR2,v_table_name VARCHAR2) IS
SELECT column_name FROM dba_tab_columns
WHERE owner=UPPER(v_schemaname) AND table_name=v_table_name
AND column_id < 6 ORDER BY column_id ASC;
t_col curcol%ROWTYPE;
i NUMBER;
v_errorcode NUMBER;
v_errormsg VARCHAR2(255);
v_line VARCHAR2(255);
v_sep VARCHAR2(5);
v_map VARCHAR2(30) := 'colmap = ' || UPPER(schemaname) ||' ';
v_return INTEGER:=0;
Error 24342
v_handle UTL_FILE.FILE_TYPE;
Carl Dudley - 30
Schema Changes - Package Body (2)
BEGIN
v_handle := UTL_FILE.FOPEN(Directory,filename,'w');
FOR t_tab IN curtab LOOP
v_line := NULL; v_sep := NULL; i:=1;
FOR t_col IN curcol(SchemaName,t_tab.table_name) LOOP
v_line := v_line||v_sep||TO_CHAR(i)||', '||t_col.column_name;
v_sep := ', ';
i:= i+1;
END LOOP;
UTL_FILE.PUT_LINE( v_handle,v_map||t_tab.table_name||' ('||v_line||');');
UTL_FILE.FFLUSH(v_handle);
dbms_output.put_line(v_map||t_tab.table_name||' ('||v_line||');');
END LOOP;
UTL_FILE.FFLUSH(v_handle); UTL_FILE.FCLOSE(v_handle);
RETURN(v_return);
EXCEPTION
WHEN OTHERS THEN
v_errorcode := SQLCODE;
v_errormsg := SUBSTR(RTRIM(LTRIM(SQLERRM)),1,200);
dbms_output.put_line('error : >');
dbms_output.put_line(v_errormsg);
IF UTL_FILE.IS_OPEN(v_handle) then
UTL_FILE.FFLUSH(v_handle); UTL_FILE.FCLOSE(v_handle);
END IF;
RETURN(-1);
Error 24342
END logmnr;
END filesave;
Carl Dudley - 31
Construction of logmnr.opt
Carl Dudley - 32
Placeholder Data
Changes to the ename column in freds emp table will be shown in the
first set (PH1...) of placeholder columns
Undo and redo values for any transaction making changes to ename in
the emp table can be seen in the ph1_undo and ph1_redo columns
The SQL can also be seen in sql_redo and sql_undo, but the
placeholders make searching for the information much easier
Carl Dudley - 33
Tracking DDL Statements
Carl Dudley - 34
Table Creation
Carl Dudley - 35
Trigger Creation
Evidence of trigger creation can be seen in sql_redo
Carl Dudley - 36
Oracle9i LogMiner - Release 1
Full support for analysis of DDL statements
Carl Dudley - 37
Oracle9i LogMiner Dictionary Usage (1)
Data dictionary can be extracted into the redo stream with new option
EXECUTE dbms_logmnr_d.build
(options => dbms_logmnr_d.STORE_IN_REDO_LOGS);
No dictionary file to be managed
Dictionary is backed up via the redo logs
-- Produces lots of redo (minimum 12Mb) - but faster than flat file
Database must be in archivelog mode
No DDL allowed during extraction, so dictionary is consistent
EXECUTE dbms_logmnr.start_logmnr
(options => dbms_logmnr.DICT_FROM_REDO_LOGS);
Carl Dudley - 38
Oracle9i LogMiner Dictionary Usage (2)
The online data dictionary can also be used to analyze the logs
Available when database is open
Specify the following in dbms_logmnr.start_logmnr procedure
EXECUTE dbms_logmnr.start_logmnr
(options => dbms_logmnr.DICT_FROM_ONLINE_CATALOG);
Use this to analyze recent redo logs or when the structure of objects
under test has not changed
Absence of mismatches between online dictionary and redo
log contents is assumed
Carl Dudley - 39
Oracle9i LogMiner Dictionary Usage (3)
EXECUTE dbms_logmnr.start_logmnr
(options => dbms_logmnr.DICT_FROM_REDO_LOGS
+ dbms_logmnr.DDL_DICT_TRACKING);
Carl Dudley - 40
Oracle9i LogMiner Support for DDL
Now shows DDL (as originally typed) plus details of user and process
Carl Dudley - 41
Oracle9i Supplemental Logging
Carl Dudley - 42
Oracle9i Supplemental Logging Example
Carl Dudley - 43
Table Level Supplemental Logging
Specify groups of columns to be logged
ALTER TABLE emp
ADD SUPPLEMENTAL LOG GROUP emp_log (ename,sal,comm);
Carl Dudley - 44
Oracle9i Query by Data Value
mine_value
Returns actual value of data being changed
Can mine data from using redo_value and undo_value in
v$logmnr_contents
SELECT dbms_logmnr.mine_value(redo_value,FRED.EMP.SAL)
FROM v$logmnr_contents;
SELECT dbms_logmnr.mine_value(redo_value,FRED.EMP.SAL)
,sql_redo
FROM v$logmnr_contents
WHERE dbms_logmnr.mine_value(redo_value,FRED.EMP.SAL) IS NOT NULL
OR (dbms_logmnr.mine_value(redo_value,FRED.EMP.SAL) IS NULL
AND dbms_logmnr.column_present(redo_value,FRED.EMP.SAL) = 1);
Carl Dudley - 46
Oracle9i LogMiner - New Features
Populates the cscn column and can show rolled back transactions
SCN CSCN SQL_REDO
---- ---- -------------------------------------------------------------
2012 2017 insert into FRED.DEPT values(50,ARTS,PARIS);
2016 2017 delete from FRED.DEPT where ROWID = `AAACOOAEBAADPCACI;
Carl Dudley - 47
Oracle9i LogMiner Viewer
Carl Dudley - 48
Oracle9i LogMiner Viewer
Carl Dudley - 49
Oracle9i Release 2 LogMiner Logical Standby
Carl Dudley - 50
Oracle9i Release 2 LogMiner dbms_logmnr_session
Carl Dudley - 51
Oracle9i Release 2 LogMiner Persistent Sessions
Can be programmed to run continuously and wait for new redo logs
Set wait_for_log flag in
dbms_logmnr_session.create_session
Carl Dudley - 52
Oracle9i LogMiner (continued)
Carl Dudley - 53
Oracle LogMiner
Carl Dudley
Staffordshire University, UK
Carl Dudley - 54