When a long-running transaction on a read-only node holds a metadata lock (MDL) on a table, data definition language (DDL) operations on the primary node block until the transaction ends or the replica_lock_wait_timeout expires (default: 50 seconds). When the timeout fires, the DDL fails with ERROR 8007 (HY000): Fail to get MDL on replica during DDL synchronize.
Set polar_slave_work_on_nonblock_mdl_mode to ON to let DDL operations proceed on the primary node without waiting for conflicting MDLs on read-only nodes to be released.
How it works
In a PolarDB for MySQL cluster, DDL operations on the primary node must synchronize MDLs to all read-only nodes before they can complete. If a long-running transaction on a read-only node holds an MDL on the target table, MDL synchronization blocks until the transaction ends or replica_lock_wait_timeout expires.
When polar_slave_work_on_nonblock_mdl_mode is ON, DDL operations on the primary node proceed immediately without waiting for conflicting MDLs on read-only nodes. The trade-off is that a transaction on a read-only node may observe different table schemas within a single transaction if a DDL runs concurrently on the primary node.
This parameter resolves MDL blocking only when the root cause is a long-running transaction. It does not resolve blocking caused byLOCK TABLESorFLUSH TABLES— those MDLs require an explicitUNLOCK TABLESto release.
Prerequisites
Before you enable this parameter, ensure that your cluster meets all of the following conditions.
Version requirement — your cluster must meet one of the following:
PolarDB for MySQL 8.0, revision version 8.0.1.1.23 or later
PolarDB for MySQL 5.7, revision version 5.7.1.0.19 or later
PolarDB for MySQL 5.6, revision version 5.6.1.0.32 or later
To check your cluster's revision version, see Query the engine version.
Isolation level requirement — the transaction isolation level on read-only nodes must be Read Committed or Read Uncommitted. The parameter has no effect under Repeatable Read or Serializable isolation.
Diagnose MDL blocking
Before enabling the parameter, confirm that long-running transactions (not LOCK TABLES or FLUSH TABLES) are the root cause of the blocking. The parameter cannot unblock MDLs held by explicit table locks.
Step 1: On the primary node — run SHOW PROCESSLIST and check whether any row shows State = Wait for syncing with replicas. If so, a DDL is blocked waiting for MDL synchronization on a read-only node.
SHOW PROCESSLIST;Step 2: On a read-only node — identify the blocking transaction:
SELECT * FROM information_schema.innodb_log_mdl_slot WHERE slot_state = 'SLOT_ACQUIRING';If the query returns rows, a long-running transaction holds an MDL:
+---------+----------------+-----------+----------+-----------+
| slot_id | slot_state | slot_name | slot_lsn | thread_id |
+---------+----------------+-----------+----------+-----------+
| 0 | SLOT_ACQUIRING | test/t | 35025648 | thread-0 |
+---------+----------------+-----------+----------+-----------+Next steps based on the output:
| Situation | Action |
|---|---|
| Query returns rows (long-running transaction confirmed) | Enable polar_slave_work_on_nonblock_mdl_mode to prevent future occurrences. To immediately unblock the current DDL, terminate the blocking transaction using the thread_id from the output. |
| Query returns no rows | The blocking is not caused by a long-running transaction. Check for active LOCK TABLES or FLUSH TABLES statements and release them with UNLOCK TABLES. |
Enable the parameter
Log on to the PolarDB console.
In the upper-left corner, select the region where your cluster is deployed.
Find the cluster and click its ID.
In the left-side navigation pane, choose Settings and Management > Parameters.
Find
loose_polar_slave_work_on_nonblock_mdl_modeand click Modify Parameter.
Click Submit Changes. In the Save Changes dialog box, click OK.

Limitations and side effects
| Category | Detail |
|---|---|
| Scope | Applies only to read-only nodes. Has no effect on the primary node. |
| Lock/flush tables | Cannot bypass MDLs held by LOCK TABLES or FLUSH TABLES. Release those locks with UNLOCK TABLES. |
| Parallel query timeout | After enabling this parameter, MDL synchronization failures may still occur if parallel queries on read-only nodes run longer than replica_lock_wait_timeout (default: 50 seconds). |
| Schema consistency | When the parameter is ON, a transaction on a read-only node may observe different table schemas before and after a concurrent DDL on the primary node. See the section below for an example. |
Schema consistency behavior when the parameter is ON
When polar_slave_work_on_nonblock_mdl_mode is ON, a DDL on the primary node no longer waits for in-flight transactions on read-only nodes. As a result, a single transaction on a read-only node can observe two different table schemas.
| Read-only node (Session 1) | Primary node (Session 2) |
|---|---|
BEGIN; | |
SELECT * FROM test.t; — returns column a only | |
ALTER TABLE test.t ADD COLUMN b INT; — succeeds immediately | |
SELECT * FROM test.t; — returns columns a and b | |
COMMIT; |
The second SELECT in Session 1 returns the updated schema because the DDL in Session 2 completed while the transaction was still open.
When the parameter is OFF (default), the DDL in Session 2 blocks until Session 1 commits or replica_lock_wait_timeout expires, returning ERROR 8007 (HY000): Fail to get MDL on replica during DDL synchronize.
Contact us
If you have any questions about DDL operations, please contact technical support.