All Products
Search
Document Center

PolarDB:Manage binary logs by using SQL statements

Last Updated:Mar 28, 2026

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.

StatementPurpose
START MASTERStarts binary log generation
STOP MASTERStops binary log generation
RESET MASTERDeletes all binary log files and restarts numbering
FLUSH LOGSRotates the active binary log file (single-stream only)

Prerequisites

Before you begin, ensure that you have:

Usage notes

  • Without the WITH clause, statements operate on binary logs in single-stream mode.

  • With the WITH clause, statements operate on the specified binary logs in multi-stream mode.

  • The stream group name in the WITH clause 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

ParameterDescription
stream_group_nameThe 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.

Warning

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

ParameterDescription
stream_group_nameThe 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:

  1. Run STOP MASTER to stop binary log generation.

  2. Run RESET MASTER to delete all binary log files. New files are generated from the current point in time, starting at binlog.000001.

  3. Run START MASTER to restart binary log generation.

Syntax

RESET MASTER [WITH stream_group_name]

Parameters

ParameterDescription
stream_group_nameThe 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 |
+---------------+-----------+