Enabling MariaDB binary log annotation - Amazon Relational Database Service

Enabling MariaDB binary log annotation

In a MariaDB DB instance, you can use the Annotate_rows event to annotate a row event with a copy of the SQL query that caused the row event. This approach provides similar functionality to enabling the binlog_rows_query_log_events parameter on an RDS for MySQL DB instance.

You can enable binary log annotations globally by creating a custom parameter group and setting the binlog_annotate_row_events parameter to 1. You can also enable annotations at the session level, by calling SET SESSION binlog_annotate_row_events = 1. Use the replicate_annotate_row_events to replicate binary log annotations to the replica instance if binary logging is enabled on it. No special privileges are required to use these settings.

The following is an example of a row-based transaction in MariaDB. The use of row-based logging is triggered by setting the transaction isolation level to read-committed.

CREATE DATABASE IF NOT EXISTS test; USE test; CREATE TABLE square(x INT PRIMARY KEY, y INT NOT NULL) ENGINE = InnoDB; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; BEGIN INSERT INTO square(x, y) VALUES(5, 5 * 5); COMMIT;

Without annotations, the binary log entries for the transaction look like the following:

BEGIN /*!*/; # at 1163 # at 1209 #150922 7:55:57 server id 1855786460 end_log_pos 1209 Table_map: `test`.`square` mapped to number 76 #150922 7:55:57 server id 1855786460 end_log_pos 1247 Write_rows: table id 76 flags: STMT_END_F ### INSERT INTO `test`.`square` ### SET ### @1=5 ### @2=25 # at 1247 #150922 7:56:01 server id 1855786460 end_log_pos 1274 Xid = 62 COMMIT/*!*/;

The following statement enables session-level annotations for this same transaction, and disables them after committing the transaction:

CREATE DATABASE IF NOT EXISTS test; USE test; CREATE TABLE square(x INT PRIMARY KEY, y INT NOT NULL) ENGINE = InnoDB; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; SET SESSION binlog_annotate_row_events = 1; BEGIN; INSERT INTO square(x, y) VALUES(5, 5 * 5); COMMIT; SET SESSION binlog_annotate_row_events = 0;

With annotations, the binary log entries for the transaction look like the following:

BEGIN /*!*/; # at 423 # at 483 # at 529 #150922 8:04:24 server id 1855786460 end_log_pos 483 Annotate_rows: #Q> INSERT INTO square(x, y) VALUES(5, 5 * 5) #150922 8:04:24 server id 1855786460 end_log_pos 529 Table_map: `test`.`square` mapped to number 76 #150922 8:04:24 server id 1855786460 end_log_pos 567 Write_rows: table id 76 flags: STMT_END_F ### INSERT INTO `test`.`square` ### SET ### @1=5 ### @2=25 # at 567 #150922 8:04:26 server id 1855786460 end_log_pos 594 Xid = 88 COMMIT/*!*/;