Moving a collocation
You can move a collocation from one member cluster to another in a database cluster group for Aurora by running a data movement job. To understand how a move works, see Moving data between member clusters. To see what a job moves and what can block it, see Data movement considerations.
Before you begin
Complete the following before you start a move.
Requirements
Make sure that these conditions hold:
-
Routing is enabled for the database cluster group for Aurora, and you can connect to the routing endpoint. See Finding the routing endpoint name.
-
Data mappings describe the objects that you move, and the data mappings for all of those objects share the same collocation. See Data mappings and collocations.
-
Your router user holds
dbclustergroup_move_admin. The privilege is administrative in scope. It permits a move of any collocation between any member clusters in the group. -
No other data movement job is active in the group.
A job moves at most 10,000 tables and 1 TiB of table data, indexes included. Plan collocations under these limits.
Confirm the objects that will be moved
-
At the routing endpoint, read the data mappings of the collocation that you intend to move. See Data mappings and collocations.
SELECT * FROM dbclustergroup_sys.data_mappings WHERE router_collocation_group = 'COLLOCATION_NAME'; -
Check that the result lists only the objects that you intend to move. If it lists other objects, regroup them first. For each of them, set
router_collocation_groupandmember_cluster_aliastogether in oneUPDATE. Use the current alias to keep the data where it is. -
Check that the objects are eligible to be moved. See Data movement considerations.
Check for queries that go directly to the source member cluster
Check whether any application sends queries directly to the moving objects on the source member cluster, instead of through the routing endpoint. If you want these queries to continue working, modify your application to send them through the routing endpoint before you start the move. For more information, see Access to the moving objects.
Prepare the destination member cluster
For a table mapping, make sure that the database that contains the table exists on the destination member cluster.
A job fails during the precheck if an object that it moves already exists on the destination member cluster.
Confirm the users and roles that have access
Identify the users and roles that have access to the moving objects on the source member cluster. Check whether those users and roles exist on the destination member cluster. To keep their access after the cutover, see Preserving grants.
Back up the source member cluster and export the mappings (optional)
-
In the AWS CLI or the console, back up the source member cluster. The move drops the source copy after the cutover. See Backing up and restoring a database cluster group for Aurora.
-
At the routing endpoint, export your data mappings so that you have a record of them from before the move. See Exporting the mappings before and after a change.
Starting a data movement job
To move collocations
-
Connect to the routing endpoint in a session that isn't pinned. Run the move statement with
EXPLAINin front of it, and read the result.EXPLAINchecks the move without starting a job, so a wrong collocation name or member cluster alias surfaces while the source is still authoritative. For the syntax and every option, see EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION and ALTER DBCLUSTERGROUP MOVE COLLOCATION.EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATIONCOLLOCATION_NAMEFROMSOURCE_CLUSTERTOTARGET_CLUSTER; -
At the routing endpoint, run the same statement without
EXPLAIN, and note the job identifier that it returns in theJOB_IDcolumn. You use the job identifier to monitor, cut over, and cancel the job.ALTER DBCLUSTERGROUP MOVE COLLOCATIONCOLLOCATION_NAMEFROMSOURCE_CLUSTERTOTARGET_CLUSTER;To choose when the cutover happens, or to keep users' grants, add the options. For example:
ALTER DBCLUSTERGROUP MOVE COLLOCATIONCOLLOCATION_NAMEFROMSOURCE_CLUSTERTOTARGET_CLUSTERMANUAL_CUTOVER = 1, PRESERVE_GRANTS_FOR = ('app_user'); -
At the routing endpoint, monitor the job by reading the job's row in the
move_infoview. See Reading move status. -
At the routing endpoint, if you started the move with
MANUAL_CUTOVER = 1, run the cutover when you are ready for it. See To cut over manually. -
At the routing endpoint, continue to monitor the job's row in the
move_infoview untilstatusshowsCompleted,Error, orCancelled. The job showsCompletedafter the cutover,Errorif the job fails, andCancelledif you cancel it.
Preserving grants
After the cutover, the routing layer sends queries on the moved objects to the destination member cluster. A move doesn't automatically preserve grants on the moving objects. The destination member cluster refuses a user who lacks privileges on the moved objects, so a query that succeeded on the source member cluster might now fail. Either grant the users their permissions on the destination, or use the PRESERVE_GRANTS_FOR option of the move statement.
-
PRESERVE_GRANTS_FORtakes a comma-separated list of users and roles in parentheses, for examplePRESERVE_GRANTS_FOR = ('app_user', 'report_user'). -
Each account that you list must exist on both the source and the destination member cluster. A move copies only direct grants on the moving objects, not privileges that a user holds through role membership, so grant role memberships on the destination yourself.
-
The move fails if you list an account that has no direct grants on the moving objects.
-
Name each account as
'. An account named without a host is treated asUSER'@'HOST'', as in a MySQLUSER'@'%'GRANTstatement.
Reading move status
At the routing endpoint, read the job's row in the move information view, filtered on the job identifier.
SELECT job_id, status, phase, progress_details, errors, warnings, cleanup_status, updated_at FROM dbclustergroup_data_movement.move_info WHERE job_id = 'JOB_ID';
For information on the output, see move_info.
Amazon RDS events for a move
The database cluster group for Aurora also emits Amazon RDS events for a move, with the source type db-cluster-group. To read them, run aws rds describe-events --source-type db-cluster-group. For more information, see Amazon RDS events for database cluster groups for Aurora.
Cutting over
For information about automatic and manual cutover, see Cutover.
To cut over manually
-
At the routing endpoint, read the job's row in
move_info. -
Check that the job is in the CDC Replication phase. The replication lag is in
progress_details. -
At the routing endpoint, run the cutover statement.
ALTER DBCLUSTERGROUP CUTOVER JOB 'JOB_ID' MAX_REPLICATION_LAG_SECONDS =SECONDS;MAX_REPLICATION_LAG_SECONDSis optional. The cutover command is rejected unless the replication lag is below this bound. The accepted range is 1 to 300 seconds, with a default of 10 seconds. -
At the routing endpoint, read
move_infountil the job readsCompleted. The statement returns when the routing layer records the request, not when the cutover ends.
A large MAX_REPLICATION_LAG_SECONDS value can lengthen the time that reads and writes to the moving objects are rejected.
A query on the moving objects during the cutover fails. For how to handle that, see Cutover.
Canceling a move
Cancel a move to abandon it before the cutover. After the cutover begins, the routing layer rejects the cancel. Wait for the job to end.
To cancel a move
-
At the routing endpoint, read the job's
statusandphaseinmove_info. Continue only ifstatusreadsRunningorPausedand the phase comes beforeCutoverInit. -
At the routing endpoint, run the cancel statement.
ALTER DBCLUSTERGROUP CANCEL JOB 'JOB_ID'; -
At the routing endpoint, read
move_infoagain to confirm that the job readsCancelled. The statement returns when the routing layer records the request, not when the cancel ends. The job can readCancelledbefore the cleanup completes, so readcleanup_statusto see whether cleanup has finished.
A cancel drops the objects that the move created on the destination member cluster, and leaves the source objects and the data mappings as they were. You can't cancel or cut over a job that has ended.
Related pages
For related tasks and concepts, see the following pages: