Using LogMiner

来源:互联网 发布:c语言编程水仙花数 编辑:程序博客网 时间:2024/04/28 05:50

Oracle links:

Using LogMiner
1.date format
ALTER SESSION SET NLS_DATE_FORMAT = 'dd-mon-yyyy hh24:mi:ss';
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
Requirement:
■ Source and mining database
– Both the source database and the mining database must be running on the same hardware platform.
– The mining database can be the same as, or completely separate from, the source database.
– The mining database must run the same release or a later release of the Oracle Database software as the source database.
– The mining database must use the same character set (or a superset of the character set) used by the source database.
■ LogMiner dictionary
– The dictionary must be produced by the same source database that generates the redo log files that LogMiner will analyze.
■ All redo log files:
– Must be produced by the same source database.
– Must be associated with the same database RESETLOGS SCN.
– Must be from a release 8.0 or later Oracle Database. However, several of the LogMiner features introduced as of release 9.0.1 work only with redo log files produced on an Oracle9i or later database.
LogMiner does not allow you to mix redo log files from different databases or to use a dictionary from a different database than the one that generated the redo log files to be analyzed.

Steps in a Typical LogMiner Session
1.SET DATE FORMAT
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
2.Enable Supplemental Loggining
At the very least,enable minimal supplemental logging, as follows:
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
3.Extract a LogMiner Dictionary --any method
3.1Using the Online Catalog
This is the most efficient and easy-to-use option.
EXECUTE DBMS_LOGMNR.START_LOGMNR(-
OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
3.2Extracting a LogMiner Dictionary to the Redo Log File
To extract a LogMiner dictionary to the redo log files, the database must be open and in ARCHIVELOG mode and archiving must be enabled.
EXECUTE DBMS_LOGMNR_D.BUILD( -
OPTIONS=> DBMS_LOGMNR_D.STORE_IN_REDO_LOGS);
3.3Extracting the LogMiner Dictionary to a Flat File
Be sure that no DDL operations occur while the dictionary is being built.
a. To specify a directory, set the initialization parameter, UTL_FILE_DIR, in the initialization parameter file.
For example, to set UTL_FILE_DIR to use /oracle/database as the directory where the dictionary file is placed, place the following in the initialization
parameter file:UTL_FILE_DIR = /oracle/database
Remember that for the changes to the initialization parameter file to take effect,
you must stop and restart the database.
b. STARTUP
c. Execute the PL/SQL procedure DBMS_LOGMNR_D.BUILD. Specify a file name for the dictionary and a directory path name for the file. This procedure creates the dictionary file. For example, enter the following to create the file dictionary.ora in /oracle/database:
EXECUTE DBMS_LOGMNR_D.BUILD('dictionary.ora', -
'/oracle/database/', -
DBMS_LOGMNR_D.STORE_IN_FLAT_FILE);
You could also specify a file name and location without specifying the STORE_IN_FLAT_FILE option. The result would be the same
3.4Redo Log File Options
a.■ Automatically
LogMiner will use the database control file to find and add redo log files that
satisfy your specified time or SCN range to the LogMiner redo log file list. For example:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
EXECUTE DBMS_LOGMNR.START_LOGMNR( -
STARTTIME => '01-Jan-2003 08:30:00', -
ENDTIME => '01-Jan-2003 08:45:00', -
OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + -
DBMS_LOGMNR.CONTINUOUS_MINE);
b.■ Manually
For example, enter the following to specify /oracle/logs/log1.f :
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -
LOGFILENAME => '/oracle/logs/log1.f', -
OPTIONS => DBMS_LOGMNR.NEW);
If add more redo log files. For example, enter the following to add /oracle/logs/log2.f:
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -
LOGFILENAME => '/oracle/logs/log2.f', -
OPTIONS => DBMS_LOGMNR.ADDFILE);
4.Specify Redo Log Files for Analysis
a.Ensure instance is open.
b.Create a list of redo log files

EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -
LOGFILENAME => '/oracle/logs/log1.f', -
OPTIONS => DBMS_LOGMNR.NEW);
c.Add more redo logs
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -
LOGFILENAME => '/oracle/logs/log2.f', -
OPTIONS => DBMS_LOGMNR.ADDFILE);
you could simply enter the following:
EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -
LOGFILENAME=>'/oracle/logs/log2.f')
d. If desired, remove redo log file
EXECUTE DBMS_LOGMNR.REMOVE_LOGFILE( -
LOGFILENAME => '/oracle/logs/log2.f');
5.Start LogMiner
Execute the DBMS_LOGMNR.START_LOGMNR procedure to start LogMiner
a.If you are specifying the name of a flat file LogMiner dictionary
EXECUTE DBMS_LOGMNR.START_LOGMNR( -
DICTFILENAME =>'/oracle/database/dictionary.ora');
b.If you are not specifying a flat file dictionary name

EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS =>
DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
6.Query V$LOGMNR_CONTENT
Filtering Data by Time

ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
EXECUTE DBMS_LOGMNR.START_LOGMNR( -
DICTFILENAME => '/oracle/database/dictionary.ora', -
STARTTIME => '01-Jan-2008 08:30:00', -
ENDTIME => '01-Jan-2008 08:45:00'-
OPTIONS => DBMS_LOGMNR.CONTINUOUS_MINE);
SELECT *
FROM v$logmnr_contents;
WHERE sql_redo LIKE '%%';
7.End the LogMiner Session
EXECUTE DBMS_LOGMNR.END_LOGMNR

原创粉丝点击