View a markdown version of this page

Moving a collocation - Amazon Aurora

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.

Note

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

  1. 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';
  2. 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_group and member_cluster_alias together in one UPDATE. Use the current alias to keep the data where it is.

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

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

  2. 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
  1. Connect to the routing endpoint in a session that isn't pinned. Run the move statement with EXPLAIN in front of it, and read the result. EXPLAIN checks 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 COLLOCATION COLLOCATION_NAME FROM SOURCE_CLUSTER TO TARGET_CLUSTER;
  2. At the routing endpoint, run the same statement without EXPLAIN, and note the job identifier that it returns in the JOB_ID column. You use the job identifier to monitor, cut over, and cancel the job.

    ALTER DBCLUSTERGROUP MOVE COLLOCATION COLLOCATION_NAME FROM SOURCE_CLUSTER TO TARGET_CLUSTER;

    To choose when the cutover happens, or to keep users' grants, add the options. For example:

    ALTER DBCLUSTERGROUP MOVE COLLOCATION COLLOCATION_NAME FROM SOURCE_CLUSTER TO TARGET_CLUSTER MANUAL_CUTOVER = 1, PRESERVE_GRANTS_FOR = ('app_user');
  3. At the routing endpoint, monitor the job by reading the job's row in the move_info view. See Reading move status.

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

  5. At the routing endpoint, continue to monitor the job's row in the move_info view until status shows Completed, Error, or Cancelled. The job shows Completed after the cutover, Error if the job fails, and Cancelled if 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_FOR takes a comma-separated list of users and roles in parentheses, for example PRESERVE_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 'USER'@'HOST'. An account named without a host is treated as 'USER'@'%', as in a MySQL GRANT statement.

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

  1. At the routing endpoint, read the job's row in move_info.

  2. Check that the job is in the CDC Replication phase. The replication lag is in progress_details.

  3. At the routing endpoint, run the cutover statement.

    ALTER DBCLUSTERGROUP CUTOVER JOB 'JOB_ID' MAX_REPLICATION_LAG_SECONDS = SECONDS;

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

  4. At the routing endpoint, read move_info until the job reads Completed. The statement returns when the routing layer records the request, not when the cutover ends.

Important

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
  1. At the routing endpoint, read the job's status and phase in move_info. Continue only if status reads Running or Paused and the phase comes before CutoverInit.

  2. At the routing endpoint, run the cancel statement.

    ALTER DBCLUSTERGROUP CANCEL JOB 'JOB_ID';
  3. At the routing endpoint, read move_info again to confirm that the job reads Cancelled. The statement returns when the routing layer records the request, not when the cancel ends. The job can read Cancelled before the cleanup completes, so read cleanup_status to 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.

For related tasks and concepts, see the following pages: