SELECT recid , stamp , name , sequence# as sequence, next_change# as nextChange,next_time as nextTime,completion_time as completionTime ,dictionary_begin as dictionaryBegin,dictionary_end as dictionaryEnd FROM V$ARCHIVED_LOG WHERE NEXT_CHANGE# >= ${beginScn?c} AND FIRST_CHANGE# <= ${endScn?c} AND NEXT_TIME >= to_date('${beginTime}','YYYYMMDDHH24MISS') AND FIRST_TIME <= to_date('${endTime}','YYYYMMDDHH24MISS') AND 1=1
BEGIN DBMS_LOGMNR_D.BUILD(OPTIONS=> DBMS_LOGMNR_D.STORE_IN_REDO_LOGS); end;
2.1 根据1的文件找出1之前最近的一个字典结束文件
将${minSequence?c}替换成第1步获取到的分析文件列表中最小的的sequence
1 2 3 4 5 6
SELECT recid , stamp , name , sequence# sequence, next_change# as nextChange,next_time as nextTime,completion_time as completionTime ,dictionary_begin as dictionaryBegin,dictionary_end as dictionaryEnd FROM V$ARCHIVED_LOG WHERE SEQUENCE# = ( SELECTMAX (SEQUENCE#) FROM V$ARCHIVED_LOG WHERE DICTIONARY_END ='YES' and SEQUENCE# <= ${minSequence?c} )
SELECTMIN (SEQUENCE#) FROM V$ARCHIVED_LOG WHERE DICTIONARY_END ='YES'
2.2 根据2.1文件找出2.1之前最近的一个字典开始文件
将${minSequence?c}替换成2.1找出的那个字典结束文件的序号
1 2 3 4 5 6
SELECT recid , stamp , name , sequence# sequence, next_change# as nextChange,next_time as nextTime,completion_time as completionTime ,dictionary_begin as dictionaryBegin,dictionary_end as dictionaryEnd FROM V$ARCHIVED_LOG WHERE SEQUENCE# = ( SELECTMAX (SEQUENCE#) FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN ='YES' and SEQUENCE# <= ${minSequence?c} )
3. 全部加入要分析的文件列表中
把1、2找到的文件都丢进去分析列表中 这里用freemarker语法表达如下
1 2 3 4 5
BEGIN <#list logFileNameSet as logFile> DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME =>'${logFile}'<#if logFile_index==0>,OPTIONS => DBMS_LOGMNR.NEW</#if>); </#list> END;
4. 启动logminer
直接开始即可
1 2 3 4
BEGIN DBMS_LOGMNR.START_LOGMNR ( OPTIONS => DBMS_LOGMNR.DICT_FROM_REDO_LOGS ); END;
5. 从视图中查询
如下,从v$logmnr_contents 中查询
1
select*from v$logmnr_contents where TABLE_NAME=? orderby SCN asc