LOGMNR简介
-
Logmnr 包是达梦数据库的日志分析工具,达梦提供了 JNI 接口和 C 接口,供应用程序直接调用。
-
在使用 Logmnr 包中的接口之前,需要先开启两个日志相关参数:
- 一是开启归档(设置 INI 参数 ARCH_INI 为 1);
- 二是开启在日志中记录逻辑操作的功能(设置 INI 参数 RLOG_APPEND_LOGIC 为 1、2 或者 3)。
C语言接口
添加mnr相关的ddl和lib,文件来源如下:
添加相关的头文件,来源如下:
接口函数
各个接口函数详见官网
logmnr_client_get_data函数
dmcode_t
logmnr_client_get_data(
void* conn,
lint row_num,
logmnr_content_t*** data,
lint* real_num
);
函数获取信息并存储在结构体data中
查看logmnr_content_t的定义:
struct logmnr_content_struct{
ulint64 scn; /* LSN when the current log record generated*/
ulint64 start_scn; /* LSN when the transaction started */
ulint64 commit_scn; /* LSN when the transaction ended */
schar timestamp[30]; /* Timestamp when the current log record generated */
schar start_timestamp[30]; /* Timestamp when the transaction started */
schar commit_timestamp[30]; /* Timestamp when the transaction ended */
schar xid[19]; /* The transaction identifier */
schar operation[20]; /* SQL operation for log record:
* INSERT - for insert statement
* DELETE - for delete statement
* UPDATE - for update statement
* BATCH_UPDATE - for batch update statement
* DDL - for ddl statement
* START - for transaction start
* COMMIT - for transaction commit statement
* ROLLBACK - for transaction rollback statement
* SEQ MODIFY - for sequence modify
* UNSUPPORTED - SQL operations is not currently supported */
ulint operation_code; /* SQL operation code for log record:
* 1 - INSERT
* 2 - DELETE
* 3 - UPDATE
* 4 - BATCH_UPDATE
* 5 - DDL
* 6 - START
* 7 - COMMIT
* 36 - ROLLBACK
* 37 - SEQ MODIFY
* 255 - UNSUPPORTED */
ulint roll_back; /* 1 = If the redo record was generated because of
* a partial or a full rollback of the associated transaction
* 0 = Otherwise */
sysname_t seg_owner; /* Name of the modified schema (in case the log pertains to a schema object modification) */
sysname_t table_name; /* Name of the modified table (in case the log pertains to a table modification) */
schar row_id[21]; /* Row ID of the row modified (only meaningful if the change pertains to a DML).
* This will be NULL if the redo record is not associated with a DML. */
sysname_t username; /* Name of the user who executed the transaction */
ulint rbasqn; /* Log unique serial number, start with 0 and global increment */
ulint rbablk; /* Page serial number within the log file */
ulint rbabyte; /* Byte offset within the page */
ulint data_obj; /* ID of the modified table (in case the log pertains to a table modification) */
ulint data_objv; /* Version of the modified table (in case the log pertains to a table modification) */
schar* sql_redo; /* That reconstructed SQL statement is equivalent to the original SQL statement. */
schar rs_id[33]; /* Serial number within the transaction */
ulint64 cscn; /* This column is deprecated in favor of the COMMIT_SCN column */
ulint seq; /* Serial number within the transaction, digit number for the RS_ID column */
ulint64 trxid; /* The transaction identifier, digit number for the XID column */
};