DM8归档日志挖掘
Posted yangeoooo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DM8归档日志挖掘相关的知识,希望对你有一定的参考价值。
一、配置源数据库
01查看是否开启归档
select para_name, para_value from v$dm_ini where para_name in ('ARCH_INI','RLOG_APPEND_LOGIC');
02修改dm.ini参数
设置RLOG_APPEND_LOGIC=1
03配置归档
alter database mount;
alter database add archivelog 'dest=/dmarch,type=local,file_size=500,space_limit=10240';
alter database archivelog;
alter database open;
二、源数据库模拟数据操作
create user HR identified by "HR1234567";
grant dba to HR;
CREATE TABLE HR.T_LOG_TEST (ID INT,NAME VARCHAR(50)) ;
INSERT INTO HR.T_LOG_TEST VALUES(1,'LIMING');
INSERT INTO HR.T_LOG_TEST VALUES(2,'DAMENG');
INSERT INTO HR.T_LOG_TEST VALUES(3,'TEST');
INSERT INTO HR.T_LOG_TEST VALUES(4,'HANMEIMEI');
INSERT INTO HR.T_LOG_TEST VALUES(5,'DAIWEI');
INSERT INTO HR.T_LOG_TEST VALUES(6,'JACK');
UPDATE HR.T_LOG_TEST SET ID = ID + 10 WHERE ID <10;COMMIT;
02归档
alter system archive log current;
三、配置本地数据库
01修改dm.ini参数并配置归档
select para_name, para_value from v$dm_ini where para_name in ('ARCH_INI','RLOG_APPEND_LOGIC');
02查询本地魔数
SELECT DB_MAGIC FROM V$RLOG;
LINEID DB_MAGIC
---------- --------------------
1 1394078231
03下载源端归档日志到本地(不要使用xftp下载,会损坏日志
04修改归档日志魔数(依次修改三个归档日志魔数)
dmmdf.exe TYPE=2 FILE="C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_18-55-21.log"
dmmdf.exe TYPE=2 FILE="C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_18-58-18.log"
dmmdf.exe TYPE=2 FILE="C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_19-04-37.log"
input error, input again: 6
Input the new value: 13940782
Do you want to quit and save the change to file (y/n): y
Save to file success!
05添加归档日志文件到本地库
c:\\dmdbms\\bin>disql
disql V8
username:
password:
Server[LOCALHOST:5236]:mode is normal, state is open
login used time : 14.448(ms)
SQL>
DBMS_LOGMNR.ADD_LOGFILE('C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_18-55-21.log');
DBMS_LOGMNR.ADD_LOGFILE('C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_18-58-18.log');
DBMS_LOGMNR.ADD_LOGFILE('C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_19-04-37.log');
06查询归档信息
可以通过动态视图V$LOGMNR_LOGS查询 ADD_LOGFILE 添加的归档日志文件信息,查询结果如下:
select low_scn, next_scn, low_time, high_time, log_id, filename from v$logmnr_logs;
LINEID LOW_SCN NEXT_SCN
---------- -------------------- --------------------
LOW_TIME
----------------------------------------------------------------------------------------------------
HIGH_TIME
----------------------------------------------------------------------------------------------------
LOG_ID FILENAME
----------- --------------------------------------------------------------
1 170782 172250
2021-07-08 09:56:54.000000
2021-07-08 09:56:48.168000
0 C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_18-55-21.log
LINEID LOW_SCN NEXT_SCN
---------- -------------------- --------------------
LOW_TIME
----------------------------------------------------------------------------------------------------
HIGH_TIME
----------------------------------------------------------------------------------------------------
LOG_ID FILENAME
----------- --------------------------------------------------------------
2 172251 172251
2021-07-08 09:56:48.168000
2021-07-07 19:01:58.165054
1 C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_18-58-18.log
LINEID LOW_SCN NEXT_SCN
---------- -------------------- --------------------
LOW_TIME
----------------------------------------------------------------------------------------------------
HIGH_TIME
----------------------------------------------------------------------------------------------------
LOG_ID FILENAME
----------- --------------------------------------------------------------
3 172251 172251
2021-07-07 19:01:58.165054
2021-07-07 19:04:37.074763
2 C:\\dmdbms\\ARCHIVE_LOCAL1_0x5570C5F0[0]_2021-07-07_19-04-37.log
07启动归档日志文件分析
执行ADD_LOGFILE添加日志文件后,需要调用START_LOGMNR过程启动归档日志分析,在调用时可指定START_SCN, END_SCN, START_DATE, END_DATE, OPTIONS等参数。
时间参数值可根据V
L
O
G
M
N
R
L
O
G
S
中
L
O
W
T
I
M
E
和
H
I
G
H
T
I
M
E
或
者
实
际
业
务
场
景
指
定
范
围
;
S
C
N
可
参
考
V
LOGMNR_LOGS中LOW_TIME和HIGH_TIME或者实际业务场景指定范围;SCN可参考V
LOGMNRLOGS中LOWTIME和HIGHTIME或者实际业务场景指定范围;SCN可参考VLOGMNR_LOGS视图中LOW_SCN和NEXT_SCN来指定。
OPTIONS参数参考如下表所列的可选模式,各模式可以通过 + 或者按位或来进行组合。其它位的值如 1、4、8 等目前不支持,配置后不会报错,但是没有效果。例如,组合全部模式,则取值2+16+64+2048=2130,那么 OPTIONS 值就是 2130。
一个会话上仅能START一个LOGMNR,即只能执行一次START_LOGMNR,若要重新START需要执行终止操作,见步骤6。这里以不指定时间范围和SCN范围为例,启动所有添加的归档日志文件的分析,语句参考如下(OPTIONS=2066是2+16+2048的组合):
DBMS_LOGMNR.START_LOGMNR(OPTIONS=>2066);
DMSQL executed successfully
used time: 17.266(ms). Execute id is 412.
四、查看归档日志文件分析结果
01查看日志分析过程
select * from V$LOGMNR_PARAMETERS;
LINEID START_DATE
---------- ----------------------------------------------------------------------------------------------------
REQUIRED_START_DATE
----------------------------------------------------------------------------------------------------
END_DATE
----------------------------------------------------------------------------------------------------
START_SCN REQUIRED_START_SCN END_SCN OPTIONS INFO STATUS
-------------------- -------------------- -------------------- ----------- ---- -----------
1 1988-01-01 00:00:00.000000
NULL
2110-12-31 00:00:00.000000
0 0 -1 2066 NULL 0
used time: 0.449(ms). Execute id is 413.
02查看分析结果
执行START_LOGMNR后,可以通过动态视图V$LOGMNR_CONTENTS查看归档日志文件的分析结果,语句如下:
SQL> SELECT OPERATION_CODE , OPERATION, SCN, SQL_REDO, TIMESTAMP ,SEG_OWNER, TABLE_NAME FROM V$LOGMNR_CONTENTS WHERE TABLE_NAME is not null;
LINEID OPERATION_CODE OPERATION SCN
---------- -------------- --------- --------------------
SQL_REDO
-----------------------------------------------------------------------------------------------------------
TIMESTAMP
----------------------------------------------------------------------------------------------------
SEG_OWNER TABLE_NAME
--------- ----------------------
1 5 DDL 172132
create user HR identified by "HR1234567";
2021-07-08 09:56:24.811000
NULL
LINEID OPERATION_CODE OPERATION SCN
---------- -------------- --------- --------------------
SQL_REDO
-----------------------------------------------------------------------------------------------------------
TIMESTAMP
----------------------------------------------------------------------------------------------------
SEG_OWNER TABLE_NAME
--------- ----------------------
2 5 DDL 172168
grant dba to HR;
2021-07-08 09:56:28.193000
NULL
LINEID OPERATION_CODE OPERATION SCN
---------- -------------- --------- --------------------
SQL_REDO
-----------------------------------------------------------------------------------------------------------
TIMESTAMP
----------------------------------------------------------------------------------------------------
SEG_OWNER TABLE_NAME
--------- ----------------------
3 5 DDL 172183
CREATE TABLE HR.T_LOG_TEST (ID INT,NAME VARCHAR(50)) ;
2021-07-08 09:56:33.218000
NULL T_LOG_TEST
used time: 1.168(ms). Execute id is 414.
终止归档日志文件分析
归档日志分析完毕后,执行如下语句结束归档日志分析。
SQL> DBMS_LOGMNR.END_LOGMNR();
DMSQL executed successfully
used time: 0.412(ms). Execute id is 415
执行该语句后查询V
L
O
G
M
N
R
L
O
G
S
和
V
LOGMNR_LOGS和V
LOGMNRLOGS和VLOGMNR_PARAMETERS将不会有数据,此时查询V$LOGMNR_CONTENTS也会报错。此3个动态性能视图都是会话级别,其他会话无法查询该视图数据。
到此一个完整的日志挖掘分析步骤已完成,如果要重新启动归档日志的分析,需要执行此步骤后,重新执行3.4-3.7步操作。若在添加文件ADD_LOGFILE之后,想移除对该文件的分析,在执行START_LOGMNR之前,可执行REMOVE_LOGFILE删除此文件;若已经执行了START_LOGMNR,则需执行END_LOGMNR结束本次分析才能开启下一次分析操作。
五、注意
做日志挖掘时候,始终用同一个会话窗口执行sql,这样才会成功。
以上是关于DM8归档日志挖掘的主要内容,如果未能解决你的问题,请参考以下文章