All Products
Search
Document Center

PolarDB:Prevent long-running transactions on read-only nodes from blocking DDL operations

Last Updated:Oct 12, 2026

PolarDB supports the polar_slave_work_on_nonblock_mdl_mode parameter. After you enable this parameter, you can prevent long-running transactions on read-only nodes of PolarDB from blocking DDL operations on the primary node. This topic describes how to enable this parameter for PolarDB.

Limits

PolarDB cluster versions must meet one of the following requirements:

  • PolarDB for MySQL 8.0 with a revision version of 8.0.1.1.23 or later

  • PolarDB for MySQL 5.7 with a revision version of 5.7.1.0.19 or later

  • PolarDB for MySQL 5.6 with a revision version of 5.6.1.0.32 or later

Note

You can check the kernel version of your cluster by referring to Query the engine version.

The transaction isolation level on PolarDB read-only nodes must be Read Committed or Read Uncommitted for the polar_slave_work_on_nonblock_mdl_mode parameter to take effect.

polar_slave_work_on_nonblock_mdl_mode takes effect only on read-only nodes of PolarDB.

Background information

PolarDB read-only nodes run long-running transactions that continuously hold metadata locks (MDLs) on the tables that they access. These locks prevent DDL operations on the primary node of PolarDB from completing MDL synchronization. The DDL operations eventually time out and return the error ERROR 8007 (HY000): Fail to get MDL on replica during DDL synchronize.

Note

The timeout for MDL synchronization is controlled by the replica_lock_wait_timeout parameter, which defaults to 50 seconds.

When this issue occurs, on the PolarDB primary node, run the show processlist command. If the State field in the query result shows Wait for syncing with replicas, you can run the following command on a PolarDB read-only node to query the MDL information that is in the waiting state: select * from information_schema.innodb_log_mdl_slot where slot_state = "SLOT_ACQUIRING". If this command returns the following result, an MDL waiting issue exists on the PolarDB read-only node.

+---------+----------------+-----------+----------+-----------+
| slot_id | slot_state     | slot_name | slot_lsn | thread_id |
+---------+----------------+-----------+----------+-----------+
|       0 | SLOT_ACQUIRING | test/t    | 35025648 | thread-0  |
+---------+----------------+-----------+----------+-----------+

Usage notes

polar_slave_work_on_nonblock_mdl_mode can resolve only the DDL blocking caused by long-running transactions. After you enable polar_slave_work_on_nonblock_mdl_mode, you may still encounter MDL synchronization failures caused by large queries (that is, queries that take longer than the MDL synchronization timeout).

MDLs acquired by LOCK TABLES and FLUSH TABLES must be explicitly released by running UNLOCK TABLES. Therefore, polar_slave_work_on_nonblock_mdl_mode cannot resolve the MDL blocking caused by LOCK TABLES and FLUSH TABLES.

Procedure

  1. Log in to the PolarDB console。

  2. In the upper-left corner, select the region where the cluster is deployed.

  3. Find the target cluster and click its ID.

  4. In the left-side navigation pane, choose Settings and Management > Parameters.

  5. Find the target parameter loose_polar_slave_work_on_nonblock_mdl_mode and click Modify Parameter.

    In the search box, enter loose_polar_slave_work_on_nonblock_mdl_mode. You can see that the current value of this parameter for the cluster is ON, the global parameter is Yes, and the modification range is [ON|OFF]. Click Modify Parameter.

  6. After you modify the parameter, click Submit Changes. In the Save Changes dialog box, click OK.

Examples

After you enable polar_slave_work_on_nonblock_mdl_mode, the same transaction on a read-only node may see different table schemas, as shown in the following example:

  1. First, query test.t on a read-only node:

    mysql> begin;
    mysql> select * from test.t;
    +------+
    | a    |
    +------+
    |    1 |
    +------+
    1 row in set (0.00 sec)
  2. Then, perform a DDL operation on test.t on the primary node:

    mysql> alter table test.t add column b int;
    Query OK, 0 rows affected (0.32 sec)
    Records: 0  Duplicates: 0  Warnings: 0
  3. Finally, query test.t on the read-only node again:

    mysql> select * from test.t;
    +------+------+
    | a    | b    |
    +------+------+
    |    1 | NULL |
    +------+------+
    1 row in set (0.00 sec)

The preceding example shows that when polar_slave_work_on_nonblock_mdl_mode is enabled, a DDL operation on the primary node causes the same transaction on the read-only node to see a different number of columns. If you disable polar_slave_work_on_nonblock_mdl_mode, the DDL operation on the primary node keeps waiting for the transaction on the read-only node until the transaction is committed or the wait times out (error: ERROR 8007 (HY000): Fail to get MDL on replica during DDL synchronize).

Contact us

If you have questions about DDL operations, Contact us.