All Products
Search
Document Center

PolarDB:Best practices

Last Updated:Mar 28, 2026

When a DDL job fails or is interrupted, it enters the PENDING state. Any subsequent DDL statement on the affected table returns an error until you resolve the pending job. This topic describes how to diagnose the failure cause and choose the appropriate recovery action.

Decision guide

Run SHOW [FULL] DDL to query the job's current status and read the error message in the REMARK field. Based on the root cause, choose one of the following actions:

SituationActionKey constraint
The root cause is fixable (for example, duplicate data)Fix the data, then run RECOVER DDL to resume the job—
The root cause cannot be fixed and the DDL cannot completeRun REMOVE DDL to delete the jobMake sure the DDL statements in the job have not been applied before you run REMOVE DDL. If they have already been partially applied, the table status returned by SHOW may be inconsistent with the actual table status.
The table itself must be deleted and recreatedRun REMOVE DDL, then run DROP TABLE IF EXISTSAlways include IF EXISTS. Confirm the table is empty or the data is no longer needed before dropping.

Examples

The following examples walk through each action using a table that fails to add a primary key because of duplicate values.

Set up the scenario

  1. Create a table and insert rows that include a duplicate id value.

    mysql> create table test_pending (id int not null, age int) dbpartition by hash(id);
    Query OK, 0 rows affected (0.33 sec)
    mysql> insert into test_pending values(1,10),(1,20),(2,20),(3,30);
    Query OK, 4 rows affected (0.10 sec)
    mysql> select * from test_pending order by id;
    +------+------+
    | id   | age  |
    +------+------+
    |    1 |   10 |
    |    1 |   20 |
    |    2 |   20 |
    |    3 |   30 |
    +------+------+
    4 rows in set (0.10 sec)
  2. Try to add a primary key on id. The statement fails because the column contains duplicate values.

    mysql> alter table test_pending add primary key (id);
    ERROR 4636 (HY000): [f5be83373466000][10.81.69.55:3306][ddltest]ERR-CODE: [TDDL-4636][ERR_DDL_JOB_ERROR] Not all physical operations have been done successfully: expected 9,
    but done 8. Caused by: 1062:DDLTEST_1562056402230OYMK_7WW7_0001:Duplicate entry '1' for key 'PRIMARY' on `test_pending`;.
  3. Run SHOW FULL DDL to confirm the job is in the PENDING state and to read the failure details.

    mysql> show full ddl\G
    *************************** 1. row ***************************
              JOB_ID: 1106733441212637184
       PARENT_JOB_ID: 0
              SERVER: 1:102:10.81.69.55
       OBJECT_SCHEMA: ddltest
         OBJECT_NAME: test_pending
     NEW_OBJECT_NAME:
            JOB_TYPE: ALTER_TABLE
               PHASE: EXECUTE
               STATE: PENDING
            PROGRESS: 77%
          START_TIME: 2019-09-06 17:17:55.002
            END_TIME: 2019-09-06 17:17:55.273
    ELAPSED_TIME(MS): 271
            DDL_STMT: alter table test_pending add primary key (id)
              REMARK: ERR-CODE: [TDDL-4636][ERR_DDL_JOB_ERROR] Not all physical operations have been done successfully: expected 9, but done 8. Caused by: 1062:DDLTEST_1562056402
    230OYMK_7WW7_0001:Duplicate entry '1' for key 'PRIMARY' on `test_pending`;.

    The REMARK field contains two parts:

    • Not all physical operations have been done successfully: expected 9, but done 8. — Nine physical DDL statements were issued against the logical table. Eight succeeded and one failed, leaving the job in PENDING state.

    • Caused by: 1062:DDLTEST_1562056402230OYMK_7WW7_0001:Duplicate entry '1' for key 'PRIMARY' on 'test_pending'; — The physical table test_pending in the physical database DDLTEST_1562056402230OYMK_7WW7_0001 has a duplicate value 1 in the id column, so the column cannot serve as a primary key.

  4. Check the table for inconsistencies.

    mysql> check table test_pending;
    +----------------------------------------+-------+----------+-------------------------------------------------------------------------------------------------------------+
    | TABLE                                  | OP    | MSG_TYPE | MSG_TEXT                                                                                                    |
    +----------------------------------------+-------+----------+-------------------------------------------------------------------------------------------------------------+
    | ddltest_1562056402230oymk.test_pending | check | Error    | Table 'DDLTEST_1562056402230OYMK_7WW7_0001.test_pending' find incorrect columns 'id', please recreate table |
    +----------------------------------------+-------+----------+-------------------------------------------------------------------------------------------------------------+
    1 row in set (0.04 sec)
  5. Confirm that subsequent DDL statements on the table are blocked.

    mysql> drop table test_pending;
    ERROR 4644 (HY000): [f5beae39d466000][10.81.69.55:3306][ddltest]ERR-CODE: [TDDL-4644][ERR_PENDING_DDL_JOB_EXISTS] Another DDL job '1106733441212637184' with operation 'ALTER_
    TABLE' is pending on ddltest.test_pending in ddltest. Please use SHOW DDL to check it, and then recover or rollback it using RECOVER DDL or ROLLBACK DDL, or just remove it us
    ing REMOVE DDL if you confirm that the pending job can be discarded.

Option 1: Fix the data and recover the job

Use this option when the root cause is fixable. In this example, remove the duplicate row, then resume the job.

  1. Delete the duplicate row. To run the DELETE statement, log in to your PolarDB-X 1.0 instance. If an error occurs during login, connect to the backend ApsaraDB RDS for MySQL database as indicated in the error message.

    mysql> delete from test_pending where id=1 and age=20;
    Query OK, 1 row affected (0.07 sec)
    mysql> select * from test_pending order by id;
    +------+------+
    | id   | age  |
    +------+------+
    |    1 |   10 |
    |    2 |   20 |
    |    3 |   30 |
    +------+------+
    3 rows in set (0.02 sec)
  2. Run RECOVER DDL with the job ID to resume the job.

    mysql> recover ddl 1106733441212637184;
    Query OK, 0 rows affected (1.28 sec)
    mysql> show full ddl\G
    Empty set (0.00 sec)
    mysql> show create table test_pending\G
    *************************** 1. row ***************************
           Table: test_pending
    Create Table: CREATE TABLE `test_pending` (
      `id` int(11) NOT NULL,
      `age` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `auto_shard_key_id` (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 dbpartition by hash(`id`)
    1 row in set (0.02 sec)
    mysql> check table test_pending;
    +----------------------------------------+-------+----------+----------+
    | TABLE                                  | OP    | MSG_TYPE | MSG_TEXT |
    +----------------------------------------+-------+----------+----------+
    | ddltest_1562056402230oymk.test_pending | check | status   | OK       |
    +----------------------------------------+-------+----------+----------+
    1 row in set (0.10 sec)

    SHOW FULL DDL returns an empty set, confirming the job completed. The primary key on id is now in place and CHECK TABLE reports OK.

Option 2: Remove the job and drop the table

Use this option when the root cause cannot be resolved, or when you need to delete and recreate the table. Make sure the table is empty or the data is no longer needed before proceeding.

Warning

Run REMOVE DDL only after confirming that the DDL statements in the job have not been applied to the table. If they have already been partially applied, the table status returned by SHOW may be inconsistent with the actual table status.

mysql> remove ddl 1106733441212637184;
Query OK, 1 row affected (0.02 sec)
mysql> drop table if exists test_pending;
Query OK, 0 rows affected (0.44 sec)
mysql> show tables like 'test_pending';
Empty set (0.01 sec)

The job is deleted, the table is dropped, and SHOW TABLES confirms the table no longer exists. You can now recreate the table as needed.