

# ALTER DBCLUSTERGROUP MOVE COLLOCATION

Starts a data movement job that moves one collocation, with every object in it, from one member cluster of a database cluster group for Aurora to another.

## Description
<a name="databaseclustergroups-sql-move-collocation-description"></a>

The job copies the collocation to the target member cluster while the source keeps serving your application, and then performs the cutover with minimal downtime. For the cutover behavior and error codes, see [Moving data between member clusters](databaseclustergroups-data-movement.md).

A collocation is the unit of movement. A job moves whole objects, and it can't move objects from more than one collocation. For the procedure, see [Moving data between member clusters](databaseclustergroups-data-movement.md).

## Syntax
<a name="databaseclustergroups-sql-move-collocation-syntax"></a>

```sql
ALTER DBCLUSTERGROUP MOVE COLLOCATION {{collocation_group}}
  FROM {{source_member_cluster_alias}} TO {{target_member_cluster_alias}}
  [{{move_option}} [, {{move_option}}]]

{{move_option}}:
    MANUAL_CUTOVER = { 0 | 1 }
  | PRESERVE_GRANTS_FOR = ('{{user}}' [, ...])
```

## Parameters and options
<a name="databaseclustergroups-sql-move-collocation-parameters"></a>

The statement takes the following parameters.

{{collocation\_group}}  
The collocation to move, as a `router_collocation_group` value from `data_mappings`.

FROM {{source\_member\_cluster\_alias}} TO {{target\_member\_cluster\_alias}}  
The `member_cluster_alias` values of the member cluster that holds the collocation now and of the member cluster to move it to, written as identifiers, not as single-quoted strings. On Aurora MySQL, quote an alias that contains a hyphen with backticks.

MANUAL\_CUTOVER = { 0 \| 1 }  
`0`, the default, cuts over automatically when replication lag is at or below one second. An automatic job stays in the CDC Replication phase until then. `1` makes the job wait after the copy and change capture until you run [ALTER DBCLUSTERGROUP CUTOVER JOB](databaseclustergroups-sql-switch-job.md). Choose `1` when you need control over when the cutover happens.

PRESERVE\_GRANTS\_FOR = ( '{{user}}' [, ...] )  
The users and roles whose direct grants on the moved objects the job copies to the same-named users and roles on the target. The job doesn't copy privileges held through role membership, and it doesn't create a user or a role. Each user or role that you name must exist on both the source and the target, or the move fails. You can name an account with its host, as `'{{user}}'@'{{host}}'`, and an account named without a host means `'{{user}}'@'%'`, as in a `GRANT` statement.

Give each option at most once, and separate two options with a comma.

A move takes no options to widen or narrow its scope. If a precheck reports a dependent object, change the object or the collocation before you move.

## Where it runs and required privileges
<a name="databaseclustergroups-sql-move-collocation-privileges"></a>

Run the statement at the routing endpoint, outside a transaction, in a session that isn't pinned. Inside a transaction, the statement returns error 1179. The router user needs `dbclustergroup_move_admin` or `dbclustergroup_super_admin`. The privilege is administrative in scope: it permits a move of any object between any member clusters in the group, including an object that another user owns. The routing layer refuses a request from a user without it when the request arrives, not partway through the job. A move needs no extra parameter or capability setting. For the privileges for database cluster groups for Aurora, see [Privileges](databaseclustergroups-sql-reference.md#databaseclustergroups-sql-privileges).

## Usage notes
<a name="databaseclustergroups-sql-move-collocation-usage"></a>

Keep the following in mind when you use the statement.
+ Preview the move first with [EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-explain-move-collocation.md). The statement returns the job's ID (`JOB_ID`). Keep it to follow the job, cut it over, or cancel it.
+ A group runs one data movement job at a time. While a job is active, the routing layer refuses another move statement anywhere in the group and doesn't create a job. Start the next move after the active job ends and its cleanup completes. Read `cleanup_status` in `move_info`.
+ A mapping that names no collocation is in the default collocation of its member cluster, whose name is the member cluster alias. A move of that collocation moves every object on the member cluster that you mapped without a collocation. Read the number of table and database mappings that the preview reports before you start the move.
+ Before any row moves, the job runs prechecks that confirm the following:
  + The objects exist on the source and are eligible to move.
  + No conflicting object exists on the target.
  + The foreign key rules in [Limitations](databaseclustergroups-move-considerations.md#databaseclustergroups-move-considerations-limitations) hold.

  When one precheck fails, the job still runs the others, so the job reports every failure at once. On a table mapping, a trigger on the table blocks the precheck.
+ For a table mapping, create the object's database on the target first, under the same name. The owner of each object, and every user and role that you name in `PRESERVE_GRANTS_FOR`, must already exist on the target. Grant role memberships there yourself.
+ While the job runs, it blocks DDL on the source objects. You can query the moving objects directly on the source member cluster until the cutover. After the cutover, those queries fail because the destination member cluster now holds the objects. You can't query the objects that the job creates on the destination member cluster until the cutover completes.
+ During the cutover, the job blocks reads and writes to the moving objects. For the error codes, see [Moving data between member clusters](databaseclustergroups-data-movement.md).
+ A job reads changes from the binary log. On Aurora MySQL, set the source's `binlog_format` to `ROW`, `binlog_row_image` to `FULL`, `binlog_error_action` to `ABORT_SERVER`, `binlog_transaction_compression` to OFF, and leave `PARTIAL_JSON` out of `binlog_row_value_options`, whether or not the binary log is on. If the binary log is off, the job turns it on for the duration of the move, without a restart, and the binary log uses these settings. The setting then returns to its configured value, also without a restart. The preview shows a warning when the job will turn the binary log on. If the source replicates from another server, `log_replica_updates` must be ON. The precheck fails the move otherwise.
+ When the job finishes, it drops the source copy.

## Examples
<a name="databaseclustergroups-sql-move-collocation-examples"></a>

The following example moves collocation `cg_06` from `cluster_b` to `cluster_c` and cuts over automatically.

```sql
ALTER DBCLUSTERGROUP MOVE COLLOCATION cg_06 FROM cluster_b TO cluster_c;
```

The following example waits for you to start the cutover, and copies the direct grants of `app_rw`.

```sql
ALTER DBCLUSTERGROUP MOVE COLLOCATION cg_06 FROM cluster_b TO cluster_c
  MANUAL_CUTOVER = 1, PRESERVE_GRANTS_FOR = ('app_rw');
```

## Errors
<a name="databaseclustergroups-sql-move-collocation-errors"></a>

The statement can return the following errors. A running job records its failure reason in `move_info.errors`. For all data movement errors, see [Data movement errors](databaseclustergroups-errors-movement.md).


| Code (SQLSTATE) | Message | Meaning | 
| --- | --- | --- | 
| 1227 (42000) | Access denied; you need the 'DBCLUSTERGROUP\_MOVE\_ADMIN' privilege for this operation | Your router user lacks the dbclustergroup\_move\_admin privilege. | 
| 1064 (42000) | A MySQL syntax error | The syntax of the query is invalid. | 
| 1179 (25000) | You are not allowed to execute this command in a transaction | The statement cannot be executed within an explicit transaction. Run the statement outside of a transaction. | 
| 1221 (HY000) | Only 1 active data movement job is allowed. Job {{job\_id}} is still running. Check the 'dbclustergroup\_data\_movement.move\_info' table for more details. or Only 1 active data movement job is allowed. Clean up has not yet completed for job {{job\_id}}. Check the 'dbclustergroup\_data\_movement.move\_info' table for more details. | Another job is active in the group. Wait for the active job to end and its cleanup to complete, and run the statement again. | 
| 1221 (HY000) | Cannot start MOVE because of a conflicting move on collocation group '{{collocation\_group}}'. Please try again after the operation completes. | Another data movement job is active for the collocation. | 
| 1221 (HY000) | The source '{{source\_member\_cluster\_alias}}' and the target '{{target\_member\_cluster\_alias}}' resolve to the same member cluster | The FROM and TO aliases name the same member cluster. | 
| 1221 (HY000) | Collocation '{{collocation\_group}}' has no physical objects mapped to the source member cluster '{{source\_member\_cluster\_alias}}' | There are no mappings within the collocation, or the mappings in the collocation aren't mapped to the FROM member cluster. | 

## Related statements
<a name="databaseclustergroups-sql-move-collocation-related"></a>

For more information, see the following:
+ [EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-explain-move-collocation.md)
+ [ALTER DBCLUSTERGROUP CUTOVER JOB](databaseclustergroups-sql-switch-job.md)
+ [ALTER DBCLUSTERGROUP CANCEL JOB](databaseclustergroups-sql-cancel-job.md)
+ [Reading move status](databaseclustergroups-sql-move-info.md)