View a markdown version of this page

ALTER DBCLUSTERGROUP MOVE COLLOCATION - Amazon Aurora

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

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.

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.

Syntax

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

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. 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

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.

Usage notes

Keep the following in mind when you use the statement.

  • Preview the move first with EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION. 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 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.

  • 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

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

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.

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

Errors

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.

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.

For more information, see the following: