

# Adding and removing member clusters

In a database cluster group for Aurora, you add and remove member clusters one at a time. A cluster joins as it is: the group copies no data, and the cluster's endpoints don't change. When it leaves, it keeps its data and storage. On Aurora MySQL version 8.4.900, it has no DB instances outside a group. To move data onto or off a member cluster, you move collocations, as described in [Moving data between member clusters](databaseclustergroups-data-movement.md) and [Rebalancing member clusters](databaseclustergroups-rebalancing.md).

## Adding a member cluster
<a name="databaseclustergroups-adding-members"></a>

You add an existing cluster or a new cluster with `AddDBClusterToDBClusterGroup`. On Aurora MySQL version 8.4.900, a DB cluster outside a group can't have DB instances, so it joins the group with none. The add restarts nothing, replaces nothing, and drops no connections.

**Note**  
Create the writer and readers after the cluster joins. To bring an existing Aurora MySQL 8.4 cluster, restore a snapshot of it onto version 8.4.900, then add the restored cluster. A restore onto 8.4.900 from an earlier major version, such as Aurora MySQL version 3, isn't supported.

Adding a member cluster is how you add capacity to the group. You size each member cluster with the same Aurora tools as a standalone cluster, and its instance classes, instance count, and readers stay under your control. AWS manages the routing layer and scales it automatically. Routed statements go to the writer instance of each member cluster, so readers that you add serve direct connections. A new member cluster holds no data that the routing layer uses until you map data to it or move data onto it. To spread load across member clusters, see [Rebalancing member clusters](databaseclustergroups-rebalancing.md).

### Before you add a member cluster
<a name="databaseclustergroups-gs-before-you-add-a-member-cluster"></a>

Before you add a cluster, check the following:
+ **Location and engine.** The cluster is in the group's account and AWS Region, on the group's engine, at or above the group's minimum engine version, and not part of an Aurora global database. A cluster belongs to at most one group. If the engine version is earlier than that minimum, the add request fails with an `InvalidParameterValue` error. For the number of member clusters that a group can have, see [Quotas for database cluster groups for Aurora](databaseclustergroups-limitations.md#databaseclustergroups-limitations-quotas).
+ **Network and encryption.** Joining doesn't change the cluster's network settings or its KMS key. The group has no KMS key of its own. Every member cluster is in one zone group of the AWS Region, and adding a cluster from another zone group fails. A member cluster's Availability Zones also set where the routing layer runs, as described in [Routing layer and routing endpoint](databaseclustergroups-architecture.md#databaseclustergroups-architecture-router). A new member cluster can also change the group's restorable window, as described in [Backing up and restoring a database cluster group for Aurora](databaseclustergroups-backups.md).
+ **Permissions.** Adding a cluster needs permission on both the group and the cluster. For more information, see [IAM and API permissions](databaseclustergroups-iam.md).
+ **Users.** Its member cluster users and grants match those on the other member clusters. For more information, see [Router users and routing layer privileges](databaseclustergroups-router-users.md).
+ **Windows.** Its maintenance window doesn't overlap the group's backup window.
+ **Backup retention period.** The cluster's backup retention period is at least the group's. An Aurora Serverless v2 cluster has a minimum capacity above 0 Aurora capacity units (ACUs). The cluster is `available` or `creating`, isn't an Aurora Limitless Database cluster, and has no data groups.
+ **Parameter groups.** The group doesn't check or align parameter groups. Through the routing endpoint, the routing layer sets `sql_mode`, `time_zone`, `autocommit`, `transaction_isolation`, `auto_increment_increment`, character set, and the session timeouts `wait_timeout`, `interactive_timeout`, and `net_write_timeout` on every member session. Member cluster parameter group values for these settings don't apply to routed sessions. Keep other parameters that affect how a statement is interpreted the same on every member cluster yourself.

### Adding a cluster in place
<a name="databaseclustergroups-gs-adding-a-cluster-in-place"></a>

Add one cluster at a time, and confirm each join before you map or move data onto it.

**To add a member cluster in place**

1. On the cluster and on each member cluster (direct, through each cluster endpoint), read the settings that must match. The statements follow this procedure.

1. With the AWS CLI, if the cluster's maintenance window overlaps the group's `PreferredBackupWindow`, call `ModifyDBCluster` with `--preferred-maintenance-window`.

1. With the console, the AWS CLI, or the Amazon RDS API, add the cluster to the group with its upgrade wave, from 1 to 10, as shown in the first set of tabs. A cluster that you don't assign to a wave goes in the first wave.

1. With routing, at the routing endpoint, read `dbclustergroup_sys.member_cluster_mappings` until the new cluster's row appears. Use that row's `member_cluster_alias`, never the cluster identifier, in every mapping, pin, and move. Until the row appears, the routing layer refuses a data mapping that names the new member cluster.

   ```sql
   SELECT member_cluster_alias, db_cluster_identifier FROM dbclustergroup_sys.member_cluster_mappings;
   ```

1. With routing, at the routing endpoint and outside a transaction, pin a session to the new alias, run one statement, and clear the pin.

1. At the routing endpoint, place data on the new member cluster: write data mappings for the objects that it holds, as described in [Data mappings and collocations](databaseclustergroups-data-mappings.md), or move collocations onto it, as described in [Moving data between member clusters](databaseclustergroups-data-movement.md).

------
#### [ Console ]

**To add an existing cluster to a group (console)**

1. Sign in to the AWS Management Console and open the Amazon RDS console at [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/).

1. In the navigation pane, choose **Database cluster groups**, and then choose the group.

1. On the **Member clusters** tab, choose **Add cluster**.

1. Choose **Add clusters**. The console lists only clusters that run the group's engine.

1. Select the clusters to add, and then choose **Add selected clusters**.

1. Choose **Next**, and then review the clusters.

1. Choose **Add cluster**.

To set the upgrade wave of the new member cluster in the console, see [Assigning upgrade waves](databaseclustergroups-upgrades.md#databaseclustergroups-upgrades-waves).

------
#### [ AWS CLI ]

```bash
aws rds add-db-cluster-to-db-cluster-group --region {{REGION}} \
  --db-cluster-group-identifier {{GROUP_IDENTIFIER}} --db-cluster-identifier {{CLUSTER_IDENTIFIER}} \
  --db-cluster-group-upgrade-wave {{WAVE}}
```

------
#### [ Amazon RDS API ]

Call `AddDBClusterToDBClusterGroup` with `DBClusterGroupIdentifier`, `DBClusterIdentifier`, and `DBClusterGroupUpgradeWave`.

------

**Step 1.** On each cluster (direct), read the settings that must match.

```sql
SELECT @@aurora_version, @@sql_mode, @@time_zone, @@character_set_server, @@collation_server,
       @@lower_case_table_names, @@log_bin, @@binlog_format, @@binlog_row_image;
```

**Step 5.** At the routing endpoint, pin, read the host name, and clear the pin.

```sql
SET SESSION router_cluster_pin = '{{MEMBER_CLUSTER_ALIAS}}';
SELECT @@hostname;
SET SESSION router_cluster_pin = DEFAULT;
```

The add is complete when `DescribeDBClusterGroups` lists the cluster, the group reads `available`, and, with routing, a pin to the alias answers.

## Removing a member cluster
<a name="databaseclustergroups-removing-members"></a>

A member cluster can leave the group. The cluster keeps its storage, its data, and its own automated backups. Group snapshots taken before the removal keep the cluster's data. The cluster's own automated backups expire according to the cluster's retention period, and deleting the group's automated backups later doesn't delete them.

A removal closes each open routed session whose last routed statement went to the removed member cluster, without an error. The client sees a closed connection on its next statement, for example error 2013 on Aurora MySQL. Routed sessions whose last statement went to another member cluster stay open. Reconnect the closed sessions.

A removal makes no check on data movement, data mappings, or routing rules, and it always acts as a forced removal. It interrupts a data movement in progress on the cluster. The data mappings that name the cluster stay in the group, and a statement that reaches one of them fails, because no member cluster resolves for it. Prepare the cluster's data before you remove it, as the following section describes.

**Note**  
If the member cluster runs Aurora MySQL version 8.4.900, the removal fails with an `InvalidDBClusterStateFault` error until you delete the cluster's DB instances. The cluster then leaves the group with its storage and backups but no DB instances.

### Removing a cluster from a group
<a name="databaseclustergroups-leaving-group"></a>

If the cluster holds data that applications reach through the routing endpoint, handle that data first in one of the following ways:
+ **Keep the data on the cluster.** Point those applications at the cluster's own endpoints, then delete the data mappings that name its member cluster alias. The delete removes the routing entry, not the data. For more information, see [Sending traffic through the routing layer](databaseclustergroups-routing-traffic.md).
+ **Keep the data in the group.** Move the cluster's collocations to other member clusters with data movement. The move drops the source copy when it completes. For more information, see [Moving data between member clusters](databaseclustergroups-data-movement.md).

You can't delete a scaleout table's mapping rows while the scaleout table exists. If the cluster holds member tables of a scaleout table, move those collocations to other member clusters. Before you begin, take a backup, and export the data mappings, member cluster list, and scaleout definitions, as described in [Exporting the mappings before and after a change](databaseclustergroups-changing-mappings.md#databaseclustergroups-export-mappings). Without routing, or if no data mapping names the cluster, go straight to step 6.<a name="databaseclustergroups-gs-removing-a-member-cluster"></a>

**To remove a member cluster**

1. With routing, at the routing endpoint, check that no job in `dbclustergroup_data_movement.move_info` reads `Running`.

1. At the routing endpoint, list the rows that name the cluster's alias, by `router_collocation_group`.

   ```sql
   SELECT * FROM dbclustergroup_sys.data_mappings WHERE member_cluster_alias = '{{MEMBER_CLUSTER_ALIAS}}';
   ```

1. At the routing endpoint, move each collocation that stays in the group to a remaining member cluster with capacity for it, one job at a time, scaleout collocations included. A statement that reaches two collocations stops working when they're on different member clusters.

1. For the data that you keep on the cluster, in each application's configuration, point the connections at the cluster's own endpoints.

1. At the routing endpoint, read the data mappings again, and delete each remaining row that names the alias, one at a time, with an exact single-row `WHERE`. The statements follow this procedure.

1. With the console, the AWS CLI, or the Amazon RDS API, remove the cluster from the group, as shown in the first set of tabs after this procedure.

------
#### [ Console ]

**To remove a member cluster (console)**

1. With routing, at the routing endpoint, complete steps 1 through 5 of the preceding procedure: check that no data movement is in progress, move the collocations that stay in the group, and delete the data mappings that name the cluster's alias.

1. Sign in to the AWS Management Console and open the Amazon RDS console at [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/).

1. In the navigation pane, choose **Database cluster groups**, and then choose the group.

1. On the **Member clusters** tab, select the cluster.

1. Choose **Actions**, and then choose **Remove from group**.

1. Confirm the removal.

------
#### [ AWS CLI ]

```bash
aws rds remove-db-cluster-from-db-cluster-group --region {{REGION}} \
  --db-cluster-group-identifier {{GROUP_IDENTIFIER}} --db-cluster-identifier {{CLUSTER_IDENTIFIER}}
```

------
#### [ Amazon RDS API ]

Call `RemoveDBClusterFromDBClusterGroup` with `DBClusterGroupIdentifier` and `DBClusterIdentifier`. The call can return `DBClusterGroupNotFoundFault`, `DBClusterNotFoundFault`, `InvalidDBClusterGroupStateFault`, or `InvalidDBClusterStateFault`.

------

**Step 3.** At the routing endpoint, move one collocation.

```sql
ALTER DBCLUSTERGROUP MOVE COLLOCATION `{{COLLOCATION_GROUP}}` FROM `{{MEMBER_CLUSTER_ALIAS}}` TO `{{TARGET_ALIAS}}`;
```

**Step 5.** At the routing endpoint, delete one database-level mapping row that names the alias.

```sql
DELETE FROM dbclustergroup_sys.data_mappings WHERE router_db_name = '{{ROUTER_DB}}';
```

After the removal, keep the cluster, delete it as described in [Deleting Aurora DB clusters and DB instances](USER_DeleteCluster.md), or add it to a group again. You can't delete a cluster while it's a member of a group. At the routing endpoint, check that a routed read for each moved collocation returns the expected data. If a move is refused, see [Troubleshooting data moves and schema changes](databaseclustergroups-ts-operations.md).

## Tearing down a database cluster group for Aurora
<a name="databaseclustergroups-gs-deleting-a-db-cluster-group"></a>

Before you begin, export the data mappings and definitions, as described in [Exporting the mappings before and after a change](databaseclustergroups-changing-mappings.md#databaseclustergroups-export-mappings). Take a snapshot of each member cluster that you might need, and stop application traffic to the routing endpoint.

**To tear down a database cluster group for Aurora**

1. At the routing endpoint, drop the scaleout tables, children before parents, and then the routing functions. The member tables and their data stay.

   ```sql
   DROP SCALEOUT TABLE {{ROUTER_DB}}.{{TABLE}};
   DROP SCALEOUT ROUTING FUNCTION {{ROUTING_FUNCTION}};
   ```

1. At the routing endpoint, delete the remaining data mapping rows one at a time, with an exact match, until `dbclustergroup_sys.data_mappings` returns no rows. A `DELETE` without `WHERE` removes every mapping that no scaleout table uses, up to 1,000 rows per statement. Mappings that scaleout tables use stay. Always give a `DELETE` a `WHERE` clause.

1. With the AWS CLI, remove each member cluster, one at a time, as described in [Removing a cluster from a group](#databaseclustergroups-leaving-group), until the group lists no member clusters.

1. With the AWS CLI, delete the group, as described in [Deleting a database cluster group for Aurora](databaseclustergroups-group-lifecycle.md#databaseclustergroups-group-lifecycle-delete).

1. On each member cluster (direct), drop any databases that you created only for the group. Delete the clusters that you don't need, as described in [Deleting Aurora DB clusters and DB instances](USER_DeleteCluster.md).

You can't delete a mapping row that a scaleout table uses until you drop that scaleout table.

## API reference
<a name="databaseclustergroups-member-clusters-api"></a>

For the parameters, see the [Amazon RDS API Reference](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/Welcome.html).