

# Troubleshooting data moves and schema changes

Operations on a database cluster group for Aurora change several member clusters, so a problem can leave the group mixed. Read the state first, and then decide whether to finish the operation, undo it, or wait.

## A data movement job is stuck or failed
<a name="databaseclustergroups-a-move-is-stuck-or-failed"></a>

**Symptom.** A data movement job stays in one phase, ends in `Error`, or is refused when you start it, or a read or write fails during its cutover.

**Check.** At the routing endpoint, read the job's `status`, `phase`, `errors`, `warnings`, and `progress_details`. For more information, see [move\_info](databaseclustergroups-sysviews-move-info.md) and [Reading move status](databaseclustergroups-running-a-move.md#databaseclustergroups-move-monitoring). In the AWS CLI or the console, check that both member clusters are `available`, with no pending modification and no capacity change applying. The cutover needs both member clusters. Compare `updated_at` across reads to see whether the job still progresses. If `warnings` reads `CdcConfiguration`, the job is turning on binary logging on the source, and a long-running transaction on the source can delay the start. On the source writer (direct), read the oldest transactions in `information_schema.innodb_trx`.

```sql
-- Runs at: routing endpoint. One equality only; no ORDER BY.
SELECT * FROM dbclustergroup_data_movement.move_info WHERE job_id = '{{JOB_ID}}';
```

**Cause and fix.** Find what you see in the following table.


| You see | Cause | Fix | 
| --- | --- | --- | 
| The precheck or the job fails for a foreign key | A moving table has a foreign key, into or out of the move. A move with such a table is refused | Drop the constraint before the move. For the steps, see the foreign key row in the following table | 
| A move of a collocation is refused | Another data movement job is running. The group runs one data movement job at a time | Start the next move after the running job ends and cleanup\_status reads Complete | 
| The job stays in Cdc | It waits for you (MANUAL\_CUTOVER = 1), or change capture hasn't caught up | Run CUTOVER JOB when the lag in progress\_details is below your bound. A job that you started with MANUAL\_CUTOVER = 1 stays in this phase until you run it. A job that cuts over automatically starts the cutover itself when replication lag is at or below 1 second | 
| A read or write fails during the cutover with error 63927 | During the cutover, the job refuses reads and writes to the moving objects. The cutover also ends every transaction that is open on them | Retry the statement. If the cutover ended your transaction, reconnect if needed and run the whole transaction again. For the full rule, see [Moving data between member clusters](databaseclustergroups-data-movement.md) | 
| After the cutover, routed statements to the moved data fail for the application's user | The member cluster user doesn't exist on the target | Create the user and grants on the target. Next time, create them before the cutover | 
| Other keys moved with a tenant's collocation | A collocation carries every key that its routing function maps to it, such as every key in a MOD bucket. For the routing functions, see [Routing functions](databaseclustergroups-scaleout-tables.md#databaseclustergroups-routing-function-availability). | This behavior is expected. To isolate one tenant, give it its own collocation | 

The job's `errors` column or the refused statement can also show the following.


| You see | Cause | Fix | 
| --- | --- | --- | 
| The job is in Error in the Initializing phase, and errors reads Source cluster is not active. Current status: <STATUS> | A member cluster wasn't available when the job started, for example while a group snapshot ran, or it had a pending modification or a capacity change applying | In the AWS CLI, wait until both member clusters are available with nothing pending. Then run the move again at the routing endpoint. Nothing was moved | 
| The job stays in the Initializing phase, and updated\_at doesn't change | The move hasn't started copying | In the AWS CLI, check that both member clusters are available with nothing pending. Don't start another move while the job waits, because the group refuses a second move until this job ends. If both member clusters are available with nothing pending, and updated\_at and errors don't change across several reads, cancel the job with ALTER DBCLUSTERGROUP CANCEL JOB '{{JOB\_ID}}'; at the routing endpoint. Then contact AWS Support with the job ID and the whole move\_info row before you start the move again | 
| The job is in Error in the Precheck phase for a definer | A moving view, stored routine, trigger, or event runs as an account that doesn't exist on the target | On the target member cluster (direct), create the account, or change the definer on the source. Then run the move again. List every definer in the moving databases first, because each failure can name one object | 
| The job is in Error in the Precheck phase for an object outside the move | A moving view or stored routine reads a database that isn't part of the move | Change or drop the view or routine, or put what it reads in the same move. Then run the move again | 
| The move preview lists a foreign key under Errors, or the job is in Error in the Precheck phase for one | A moving table has a foreign key, or a foreign key links the collocation with another collocation on the same member cluster | On the source member cluster (direct), save each constraint's definition with SHOW CREATE TABLE, and drop it. Preview the move again. After the move, create the constraint again on the target | 
| The job is in Error in the Precheck phase because a database is missing on the target | For a collocation mapped table by table, the table's database doesn't exist on the target | On the target member cluster (direct), create the database. Then run the move again | 
| The job is in Error, and errors names no cause that you can fix | The cause is on the side that AWS manages | Contact AWS Support with the job ID and the whole move\_info row. Don't retry the move | 
| A move is refused with error 1221 and Only 1 active data movement job is allowed | Another data movement job is running in the database cluster group for Aurora, or the cleanup of a job that ended hasn't completed. The group runs one move job at a time | Wait until the running job ends and cleanup\_status reads Complete in move\_info, then start the next move | 
| A mapping write is refused with 1205 and Metadata for collocation group '<NAME>' is being changed by another operation | The collocation's mapping rows are locked while a data movement job moves it, until the job's cleanup completes | Change the mapping after cleanup\_status reads Complete in move\_info | 
| A cutover is refused with 1297 and A data movement request for this job is still pending. Check the job status and retry once it clears. | Another cutover or cancel for the job is still being processed | Read move\_info. Send the cutover again only if the job is still in Cdc | 

To cancel a job before the cutover, or to start the cutover of a job in the CDC Replication phase, run the following statements at the routing endpoint.

```sql
-- Runs at: routing endpoint.
ALTER DBCLUSTERGROUP CANCEL JOB '{{JOB_ID}}';
ALTER DBCLUSTERGROUP CUTOVER JOB '{{JOB_ID}}' MAX_REPLICATION_LAG_SECONDS = {{SECONDS}};
```

`MAX_REPLICATION_LAG_SECONDS` is optional, and its default is 10 seconds. A job that cuts over automatically starts the cutover when replication lag is at or below 1 second. If you want to start the cutover with a larger replication lag, use the `CUTOVER JOB` statement to start the cutover manually.

After the cutover starts, the routing layer refuses a cancel, and you can't cancel a completed move. To undo a completed move, move the collocation back. For more information, see [Moving data between member clusters](databaseclustergroups-data-movement.md). For the error codes, see [Data movement errors](databaseclustergroups-errors-movement.md).

## A schema change is half done
<a name="databaseclustergroups-a-schema-change-is-half-done"></a>

**Symptom.** A schema change reached some member clusters and not others. Depending on the key, the application sees a missing table or column, or a different result shape. A matched row or a stored value can also depend on which member cluster the key routes to, with no error. Or a drift check shows a difference between member clusters.

**Check.** Compare the table definitions on every member cluster (direct), the mapping rows, and each scaleout table's definition at the routing endpoint. For the drift check, see [Detecting schema drift](databaseclustergroups-auditing.md#databaseclustergroups-auditing-drift).

The application sees `1146` or `1054` for some keys. Run `SHOW CREATE TABLE` on each member cluster endpoint, and `SHOW CREATE SCALEOUT TABLE {{ROUTER_DB}}.{{TABLE}}` at the routing endpoint.

**Cause.** The rollout stopped partway. The routing layer doesn't compare member cluster schemas, so the group stays mixed until you make the definitions match.

**Fix.** Roll the change forward or back with the following procedure.

**To finish or undo a half-done schema change**

1. In your rollout tooling, stop the rollout. While member clusters differ, don't change data mappings, routing functions, or scaleout table definitions at the routing endpoint.

1. In your rollout records, note which member clusters have which schema, so that the application can handle both until the group converges.

1. Decide whether to roll forward on the remaining member clusters, or roll back, in reverse order, on the member clusters where it ran.

1. On each member cluster that differs, one member cluster at a time, run the DDL until the definitions match. Run it on the member cluster (direct) or through a session pin at the routing endpoint. For more information, see [Running DDL through a session pin](databaseclustergroups-schema-changes.md#databaseclustergroups-pin-ddl).

   If statements for data mappings, routing functions, or scaleout tables also stopped partway, read the current rows and definitions at the routing endpoint first. Then run one statement for each object that differs, so that a failure leaves a clear state.

1. On each member cluster (direct) and at the routing endpoint, confirm that the definitions match, every mapping points at an existing table, and one routed read per mapping succeeds. Repeat the previous step until the drift check shows no difference.

1. In the application, refresh schema caches only after every member cluster has the change.

On Aurora MySQL, a routed read for each mapping looks like the following. For a scaleout table, read one known key from each collocation, sent bare.

```sql
-- Runs at: routing endpoint, from a new connection. A database-level or table-level mapping.
SELECT 1 FROM {{ROUTER_DB}}.{{ROUTER_TABLE}} LIMIT 1;

-- Runs at: routing endpoint. A scaleout table: one key for each collocation.
SELECT 1 FROM {{ROUTER_DB}}.{{ROUTER_TABLE}} WHERE {{ROUTING_KEY}} = {{KEY_VALUE}} LIMIT 1;
```

To plan a rollout that doesn't stop halfway, see [Rolling out schema changes](databaseclustergroups-schema-changes.md).

## An upgrade or restore problem
<a name="databaseclustergroups-an-upgrade-or-restore-problem"></a>

**Symptom.** An engine upgrade or a group restore is refused or stops, or a restore doesn't return what you expect.

**Check.** With the AWS CLI, follow an upgrade through the status of the group and of each member cluster, not only after the last wave. Read `MinEngineVersion` and `MaxEngineVersion` from `describe-db-cluster-groups`, and each member cluster's status, engine version, and upgrade wave from `describe-db-clusters`. The member clusters emit Amazon RDS events when an upgrade starts and completes. At the routing endpoint, check a pin to each member cluster and one routed read per mapping.

On each member cluster (direct), compare `@@aurora_version` with the other member clusters.

**Cause and fix.** The following table lists upgrade problems. For how a wave upgrade works, see [Upgrading a database cluster group for Aurora in waves](databaseclustergroups-upgrades.md).


| You see | Cause and fix | 
| --- | --- | 
| A group upgrade request is rejected | A member cluster isn't in the active state, the member clusters run different major versions, the target version is below the highest version that a member cluster runs, or a member cluster holds a staged cluster-level upgrade of the same type. Fix the condition, for example apply the staged cluster-level upgrade, and request the group upgrade again. Upgrade major versions on each member cluster | 
| The upgrade stops before any member cluster upgrades | Aurora runs pre-upgrade checks on every member cluster and stops the upgrade if any check fails. Fix the member cluster that failed its check, and request the group upgrade again | 
| An upgrade wave value is refused | Waves run from 1 to 10. Set each member cluster's wave (DBClusterGroupUpgradeWave, --db-cluster-group-upgrade-wave) in that range | 
| Every member cluster upgraded in the same wave | A member cluster that you don't assign to a wave is in the first wave. Assign waves before you request the upgrade, and read each member cluster's wave with describe-db-clusters | 
| You want to pause or stop an upgrade between waves | You can't pause or cancel a group upgrade after it starts. For a bake period between waves, run the waves as separate upgrade requests | 
| The upgrade runs past the end of the maintenance window | An upgrade that runs past the end of the window continues to completion. Assign waves so that the upgrade can complete inside your window | 
| Routed sessions drop while a wave runs | An upgrade of a member cluster in its wave drops that member cluster's routed sessions and can roll back in-flight transactions. The other member clusters keep routing. Reconnect and retry the transaction | 

The following table lists restore problems. For how group backups and restores work, see [Backing up and restoring a database cluster group for Aurora](databaseclustergroups-backups.md).


| You see | Cause and fix | 
| --- | --- | 
| You need one member cluster's data back, not the whole group | A restore from a group backup returns the whole group. Restore the member cluster from its own cluster-level backup. The restored copy is a standalone cluster and can't rejoin the group. To use restored clusters as a group, create a new group from them | 
| The restored group has more or fewer member clusters than the group has now | A point-in-time restore reproduces the group's membership at the target time. Before you restore, read the members for the target time with describe-db-cluster-group-automated-backup-members | 
| A restore failed | The restore rolls back the resources that it created, including when IAM denies the restore of one member cluster. Amazon RDS reports an authorization failure on a member cluster as an Amazon RDS event, not in the response to the restore call. Delete the new group, fix the cause in the Amazon RDS events, for example by granting the per-member permissions that your policy needs, and restore again. For the permissions, see [IAM and API permissions](databaseclustergroups-iam.md) | 
| The restored group is in an incompatible-restore state | A restored member cluster's backup retention period is shorter than the group's. The restore finished, but you can't add a member cluster to the group. Delete the group, or restore again with a group retention period that every member cluster covers. For the retention periods, see [Backing up and restoring a database cluster group for Aurora](databaseclustergroups-backups.md) | 
| A member snapshot inside a group snapshot isn't listed, can't be restored into another group, or a group snapshot can't be shared or copied | The cluster APIs can't address the member snapshots inside a group snapshot, and a member cluster's snapshot belongs to the group that took it. You can't share or copy a group snapshot. To get one member cluster's data into another account, use that member cluster's own snapshot | 

Keep the source group serving until the restored group is `AVAILABLE`, a pin to each restored alias answers, and its mappings match your export.

## Fixing data movement and group limit errors by code
<a name="databaseclustergroups-ts-operations-error-fixes"></a>

The following tables give what to do for some data movement and group limit errors, by code and a short form of the message. For the message text and cause of every error, see [Data movement errors](databaseclustergroups-errors-movement.md).

The following table covers move statements and move jobs.


| Aurora MySQL code (SQLSTATE) | Error | What to do | 
| --- | --- | --- | 
| 1064 (42000) | Aurora MySQL: You have an error in your SQL syntax | Check the syntax in [ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-move-collocation.md). | 
| None (in move\_info) | The job's status is Error, and the errors column holds the failure reason | Read the job's row in move\_info, filtered on its job ID. See [A data movement job is stuck or failed](#databaseclustergroups-a-move-is-stuck-or-failed). | 

The following table covers the error that a limit of the group's routing metadata returns.


| Aurora MySQL code (SQLSTATE) | Error | What to do | 
| --- | --- | --- | 
| 3170 (HY000, ER\_CAPACITY\_EXCEEDED) | A metadata capacity limit was reached; the operation was rolled back | Internal metadata capacity ran out, and the operation is rolled back. A member cluster reached its limit on recently changed routing metadata. The limit frees up as earlier changes age out, so wait and retry, or make fewer distinct changes. A pin to a member cluster that isn't accepting new sessions also returns error 3170, with a different message, as described in [Session and transaction errors](databaseclustergroups-errors-sessions.md). A count or size limit in [Limitations and considerations for database cluster groups for Aurora](databaseclustergroups-limitations.md) returns error 1235 (42000) instead, and the message names the limit. | 
| 3168 (HY000) | The database cluster group metadata is temporarily unavailable | Wait briefly, and then retry the statement. | 