PolarDB-X provides four SQL statements to start, stop, reset, and rotate binary logs. All statements except FLUSH LOGS support both single-stream and multi-stream modes through an optional WITH clause.
| Statement | Purpose |
|---|---|
START MASTER | Starts binary log generation |
STOP MASTER | Stops binary log generation |
RESET MASTER | Deletes all binary log files and restarts numbering |
FLUSH LOGS | Rotates the active binary log file (single-stream only) |
Prerequisites
Before you begin, ensure that you have:
A PolarDB-X instance running version 5.4.17 or later
The SUPER or REPLICATION CLIENT privilege. For details, see Manage accounts and permissions
Usage notes
Without the
WITHclause, statements operate on binary logs in single-stream mode.With the
WITHclause, statements operate on the specified binary logs in multi-stream mode.The stream group name in the
WITHclause must match the name you specified when creating the multi-stream group.
START MASTER
Starts binary log generation. Binary logs are enabled by default, so you only need this statement after running STOP MASTER.
Syntax
START MASTER [WITH stream_group_name]Parameters
| Parameter | Description |
|---|---|
stream_group_name | The name of the multi-stream group to start. Omit for single-stream mode. |
Examples
Start binary logs in single-stream mode:
START MASTER;Start binary logs for the stream group group1:
START MASTER WITH group1;STOP MASTER
Stops binary log generation.
Do not keep binary logs stopped for an extended period. While stopped, the underlying data node (DN) physical logs are cleared and cannot be restored after you restart binary logging. To configure the DN log retention period, see Local log backup.
Syntax
STOP MASTER [WITH stream_group_name]Parameters
| Parameter | Description |
|---|---|
stream_group_name | The name of the multi-stream group to stop. Omit for single-stream mode. |
Examples
Stop binary logs in single-stream mode:
STOP MASTER;Stop binary logs for the stream group group1:
STOP MASTER WITH group1;RESET MASTER
Deletes all existing binary log files and restarts numbering from binlog.000001. Run these statements in order:
Run
STOP MASTERto stop binary log generation.Run
RESET MASTERto delete all binary log files. New files are generated from the current point in time, starting atbinlog.000001.Run
START MASTERto restart binary log generation.
Syntax
RESET MASTER [WITH stream_group_name]Parameters
| Parameter | Description |
|---|---|
stream_group_name | The name of the multi-stream group to reset. Omit for single-stream mode. |
Examples
Reset binary logs in single-stream mode:
STOP MASTER;
RESET MASTER;
START MASTER;Reset binary logs for the stream group group1:
STOP MASTER WITH group1;
RESET MASTER WITH group1;
START MASTER WITH group1;FLUSH LOGS
Closes the current binary log file and opens a new one. Supported in single-stream mode only.
Syntax
FLUSH LOGS;Example
Before running FLUSH LOGS, the highest-numbered file is binlog.000004:
SHOW BINARY LOGS;+---------------+-----------+
| LOG_NAME | FILE_SIZE |
+---------------+-----------+
| binlog.000001 | 20968 |
| binlog.000002 | 10489381 |
| binlog.000003 | 10486003 |
| binlog.000004 | 361752 |
+---------------+-----------+Run FLUSH LOGS to rotate to a new file:
FLUSH LOGS;After the rolling update, the log file with the largest number changes to binlog.000005:
SHOW BINARY LOGS;+---------------+-----------+
| LOG_NAME | FILE_SIZE |
+---------------+-----------+
| binlog.000001 | 20968 |
| binlog.000002 | 10489381 |
| binlog.000003 | 10486003 |
| binlog.000004 | 361752 |
| binlog.000005 | 260 |
+---------------+-----------+