一、设置日期格式(方便查看)
SQL> alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss' scope=spfile;
System altered.
SQL>
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual ;
TO_CHAR(SYSDATE,'YY
-------------------
2018-09-19 08:33:27
SQL>
二、开启补全日志
查看补全日志是否开启:
SQL> Select
SUPPLEMENTAL_LOG_DATA_MIN,
SUPPLEMENTAL_LOG_DATA_PK,
SUPPLEMENTAL_LOG_DATA_UI,
SUPPLEMENTAL_LOG_DATA_FK,
SUPPLEMENTAL_LOG_DATA_ALL from v$database;
开启补全日志:
SQL> alter database add supplemental log data;
SQL> alter database add supplemental log data (primary key, unique,foreign key) columns;
再次查看:
SQL> Select
SUPPLEMENTAL_LOG_DATA_MIN,
SUPPLEMENTAL_LOG_DATA_PK,
SUPPLEMENTAL_LOG_DATA_UI,
SUPPLEMENTAL_LOG_DATA_FK,
SUPPLEMENTAL_LOG_DATA_ALL from v$database;
SUPPLEME SUP SUP SUP SUP
-------- --- --- --- ---
YES YES YES YES NO
SQL>
三、开启归档
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Current log sequence 8
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
Oracle instance shut down.
SQL>
SQL>
SQL> startup mount
ORACLE instance started.
Total System Global Area 839282688 bytes
Fixed Size 2217992 bytes
Variable Size 494929912 bytes
Database Buffers 335544320 bytes
Redo Buffers 6590464 bytes
Database mounted.
SQL>
SQL>
SQL> alter database archivelog;
Database altered.
SQL>
SQL>
SQL> alter database open;
Database altered.
SQL>
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
SQL>
SQL>
SQL> alter system switch logfile;
System altered.
SQL>
四、配置LogMiner工具
SQL> show parameter UTL_FILE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string
SQL>
SQL> alter system set utl_file_dir='/u03' scope=spfile;
System altered.
SQL>
SQL>
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL>
SQL> startup
ORACLE instance started.
Total System Global Area 839282688 bytes
Fixed Size 2217992 bytes
Variable Size 494929912 bytes
Database Buffers 335544320 bytes
Redo Buffers 6590464 bytes
Database mounted.
Database opened.
SQL>
SQL>
SQL> show parameter UTL_FILE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string /u03
SQL>
五、创建数据字典文件
数据字典文件是一个文本文件,使用包DBMS_LOGMNR_D来创建。如果我们要分析的数据库中的表有变化,影响到库的数据字典也发生变化,这时就需要重新创建该字典文件。另外一种情况是在分析另外一个数据库文件的重作日志时,也必须要重新生成一遍被分析数据库的数据字典文件。
SQL> begin
dbms_logmnr_d.build('dfdict.data','/u03');
end;
/
PL/SQL procedure successfully completed.
SQL>
进入操作系统目录,在/u03下已经生成了数据字典文件:dfdict.data
[root@RedHat5 u03]# ls
dfdict.data
六、创建要分析的日志文件列表
Oracle的重作日志分为两种,在线(online)和离线(offline)归档日志文件,我这里主要分析归档日志,在线日志原理一样。
6.1、查看日志组的状况
SQL> select GROUP# ,SEQUENCE# ,STATUS from v$log;