

# Moving data between member clusters

In a database cluster group for Aurora, managed data movement moves data from one member cluster to another. Use data movement to rebalance your member clusters, for example to relieve a busy member cluster, to put data on a new member cluster, or to empty a member cluster that you plan to remove.

A data movement job moves a collocation. The job copies the collocation while the source member cluster continues serving your queries, and then transfers ownership during a short cutover. To move data from several collocations, run one move for each collocation. For information about planning collocations, see [Planning collocations and headroom](databaseclustergroups-collocation-planning.md).

For instructions on running a move, see [Moving a collocation](databaseclustergroups-running-a-move.md).

**Topics**
+ [How a data movement job works](#databaseclustergroups-data-movement-how-it-works)
+ [CDC Replication](#databaseclustergroups-data-movement-cdc)
+ [Cutover](#databaseclustergroups-data-movement-cutover-writes)
+ [Access to the moving objects](#databaseclustergroups-data-movement-access)
+ [Next steps](#databaseclustergroups-data-movement-related)
+ [Moving a collocation](databaseclustergroups-running-a-move.md)
+ [Data movement considerations](databaseclustergroups-move-considerations.md)
+ [Rebalancing member clusters](databaseclustergroups-rebalancing.md)

## How a data movement job works
<a name="databaseclustergroups-data-movement-how-it-works"></a>

A job creates and synchronizes the moving objects on the destination member cluster while the source member cluster keeps serving traffic. A brief cutover then switches ownership to the destination member cluster. A data movement job consists of the following phases:


| Phase | What happens | 
| --- | --- | 
| Precheck | The job checks for issues that would prevent the move, and then creates the moving objects on the destination member cluster. | 
| Seeding | The job copies the rows from the source objects to the destination. | 
| Change Data Capture (CDC) Replication | The job replicates incremental changes from the source to the destination. This synchronizes the two copies after seeding completes. | 
| Cutover | The job blocks reads and writes to the source objects, replicates any remaining changes, and transfers ownership to the destination member cluster. | 

When a move completes, the job updates the data mappings in the collocation to reflect the new member cluster. The job does not change database or table names, so queries through the routing endpoint are routed to the destination member cluster without requiring application changes. After a successful cutover, the job drops the moved objects from the source member cluster.

## CDC Replication
<a name="databaseclustergroups-data-movement-cdc"></a>

The Change Data Capture (CDC) Replication phase reads the changes that commit on the source member cluster from the binary log. If the binary log isn't already enabled on the source member cluster, the data movement job enables it automatically, without a restart. The job keeps the binary log enabled until the job ends. After that, the setting returns to its configured value, also without a restart.

## Cutover
<a name="databaseclustergroups-data-movement-cutover-writes"></a>

By default, a data movement job cuts over automatically when the replication lag is at or below one second. To control when the cutover happens, start the job with `MANUAL_CUTOVER = 1`. With a manual cutover, the job stays in the CDC Replication phase, continuing to replicate changes, until you run the `ALTER DBCLUSTERGROUP CUTOVER JOB` command. You can also run the `ALTER DBCLUSTERGROUP CUTOVER JOB` command on a job that cuts over automatically, to cut over earlier. For the steps, see [To cut over manually](databaseclustergroups-running-a-move.md#databaseclustergroups-move-switch-manual).

During the cutover, reads and writes of the moving objects fail. A refused operation fails with error `63927` (SQLSTATE `HY000`). The message is `Cannot read `{{DATABASE}}`.`{{TABLE}}` while data movement job '{{JOB_ID}}' is in progress` for a read, or `Cannot write to `{{DATABASE}}`.`{{TABLE}}` while data movement job '{{JOB_ID}}' is in progress` for a write. The job also refuses a schema change (DDL) on a moving object at any time while it runs, with error `63927` and `Cannot execute DDL on `{{DATABASE}}`.`{{TABLE}}` while data movement job '{{JOB_ID}}' is in progress`. Retry the operation. The member cluster, not the routing layer, returns this error, so a direct connection to the source also gets it.

The cutover also ends every transaction that is open on the moving objects on the source. In that case, a routed session receives error `1180` (on `COMMIT`), `1927`, or `1317` instead of `63927`. The routing endpoint can also close the connection, which the client reports as `2013` or `2006`:
+ After `1180` or `1927`, the transaction has rolled back. Retry the whole transaction. After `1927`, the routing endpoint also closes the connection, so reconnect before you retry.
+ After `1317`, the statement stopped. If the connection is still open, roll the transaction back, and then retry it. If the connection closed, the transaction was rolled back; reconnect and retry the whole transaction. After `2013` or `2006`, the connection is gone and an open transaction was rolled back. If the error came on `COMMIT` or on an autocommit write, check whether the change was applied before you retry it.

A cutover reaches the routing layer within a short time. Until then, a query that the routing layer routes on the earlier mapping fails with error `1412`. Inside a transaction, the statement fails with error `1412`, and the transaction stays open, or, when the mappings changed after the transaction started, with error `63928` (SQLSTATE `40001`), and the transaction is rolled back. After `63928`, retry the whole transaction. Have your application retry queries that fail with any of these errors.

For more information about when the mapping change takes effect, see [Applying data mapping changes](databaseclustergroups-data-mappings.md#databaseclustergroups-when-a-data-mapping-change-takes-effect). For more information about these errors, see [Error codes for database cluster groups for Aurora](databaseclustergroups-error-reference.md).

## Access to the moving objects
<a name="databaseclustergroups-data-movement-access"></a>

You can query the moving objects through the routing endpoint at all times, except during the brief cutover.

If you connect directly to a member cluster, you can query the moving objects on the source member cluster until the cutover. After the cutover, these queries fail because the destination member cluster now holds the objects. For more information, see [Check for queries that go directly to the source member cluster](databaseclustergroups-running-a-move.md#databaseclustergroups-running-direct-queries). You can't query the objects that the job creates on the destination member cluster until the cutover completes.

## Next steps
<a name="databaseclustergroups-data-movement-related"></a>
+ For instructions on running a data movement job, see [Moving a collocation](databaseclustergroups-running-a-move.md).
+ For information about what a job moves, what can block it, and how it interacts with backups, see [Data movement considerations](databaseclustergroups-move-considerations.md).
+ For information about deciding what to move, see [Rebalancing member clusters](databaseclustergroups-rebalancing.md).
+ For information about the statements, see [Data movement statements](databaseclustergroups-sql-data-movement.md).
+ For instructions on troubleshooting a failed move, see [Troubleshooting data moves and schema changes](databaseclustergroups-ts-operations.md).