

# Upgrading a database cluster group for Aurora in waves

In a database cluster group for Aurora, you upgrade the member clusters in waves with one group operation. You assign each member cluster to a wave, and the group upgrades one wave at a time. A minor version change then reaches your member clusters in an order that you choose. Group upgrades work with routing enabled or disabled. For Aurora MySQL versions and how a cluster upgrade works, see [Database engine updates for Amazon Aurora MySQL](AuroraMySQL.Updates.md).

## How a wave upgrade works
<a name="databaseclustergroups-upgrades-how"></a>

A group upgrade covers minor engine versions, engine patches, and operating system updates. It runs in up to 10 waves within the group's maintenance window. Waves run in order, and the member clusters within a wave upgrade in parallel. A member cluster that you don't assign to a wave goes in the first wave. Before the upgrade starts, Aurora runs pre-upgrade checks on every member cluster, and the upgrade stops if any check fails. The group doesn't upgrade major versions: you upgrade them one member cluster at a time with existing Aurora operations, as described in [Major version upgrades](#databaseclustergroups-upgrades-major).

The group rejects an upgrade request unless the following conditions hold:
+ Every member cluster is available.
+ Every member cluster runs the same major version.
+ The target version is at or above the highest version that any member cluster runs.
+ No member cluster holds a staged cluster-level upgrade of the same type. After you stage a group upgrade, the group rejects a cluster-level upgrade of the same type the same way.

If a member cluster holds a staged cluster-level upgrade, apply that upgrade first, and then request the group upgrade. Operating system updates follow the same rule as engine upgrades.

The pre-upgrade checks run while every member cluster stays available. If a check fails, the upgrade stops before the group patches any member cluster. If an upgrade fails on a member cluster after patching starts, what happens next depends on the upgrade type, as the following table shows.


| Upgrade | When a member cluster fails | 
| --- | --- | 
| Aurora MySQL minor version upgrade | The member cluster rolls back, and the upgrade stops, so the waves that didn't start don't run. | 
| Aurora MySQL patch | The member cluster rolls back, and the group upgrade stops, so the waves that didn't start don't run. | 
| Operating system update | The member cluster moves to a new host, and the remaining waves continue. | 

A failure inside a wave doesn't roll back the whole wave. A member cluster that reached the target version stays on it, the others stay on the source version, and the group stays usable. To finish, request the group upgrade again while every member cluster runs the same major version: only the member clusters that aren't on the target version upgrade. You can also upgrade them at the cluster level.

You can't cancel a started group upgrade, and it doesn't pause between waves for a bake time or a manual validation step. An upgrade that runs past the end of the maintenance window continues to completion, as on a single Aurora DB cluster, so assign waves that can finish inside your window. Automatic minor version upgrade isn't available for a group. To move a group to a new minor version, request a group upgrade.

**Routed sessions during an upgrade**

A minor version upgrade of a member cluster closes the routed sessions whose last statement went to that member cluster, with no error first. On Aurora MySQL, the next statement in such a session returns error 2013 (Lost connection to MySQL server during query). The upgrade rolls back an open transaction on that member cluster. Reconnect to the routing endpoint and retry, and make sure that your retry logic also handles a connection that closes with no error. For retries, see [Retrying after an error](databaseclustergroups-queries.md#databaseclustergroups-queries-retries).

The patch keeps direct connections to the member cluster, and it doesn't affect statements for the other member clusters. The member clusters in a wave upgrade in parallel. If every member cluster is in the first wave, routed sessions across the whole group close at about the same time. To limit the effect, assign the member clusters to more than one wave, as described in [Assigning upgrade waves](#databaseclustergroups-upgrades-waves).

The routing layer isn't part of a group upgrade. AWS patches it separately, on a schedule that AWS controls. It doesn't use the group's maintenance window, and you can't move its patching into that window.

## Assigning upgrade waves
<a name="databaseclustergroups-upgrades-waves"></a>

Each member cluster has an upgrade wave, an integer from 1 to 10, that you set per member cluster. You set it when you add the cluster to the group, with `AddDBClusterToDBClusterGroup`, or later with `ModifyDBCluster` (`aws rds modify-db-cluster`) and `--db-cluster-group-upgrade-wave`. You can't set it when you create a cluster. `DescribeDBClusters` returns each member cluster's wave in `DBClusterGroupUpgradeWave`.

To limit the effect of a failed upgrade, put a small number of member clusters in the first wave, and spread the others over later waves. Assign waves so that the upgrade can complete inside your maintenance window.

**To assign an upgrade wave**

1. With the console, the AWS CLI, or the Amazon RDS API, set the member cluster's wave, as shown in the following tabs.

1. With the AWS CLI, call `DescribeDBClusters` for the member cluster, and check `DBClusterGroupUpgradeWave`.

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

**To set the upgrade wave of a member cluster (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, select the member cluster.

1. Choose **Actions**, and then choose **Edit upgrade wave**.

1. Choose the wave. Lower-numbered waves run first.

1. Save the change.

To see the wave of each member cluster, view the **Upgrade waves** section on the group's **Maintenance & backups** tab.

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

```bash
aws rds modify-db-cluster --region {{REGION}} --db-cluster-identifier {{CLUSTER_IDENTIFIER}} \
  --db-cluster-group-upgrade-wave {{WAVE}}
aws rds describe-db-clusters --region {{REGION}} --db-cluster-identifier {{CLUSTER_IDENTIFIER}} \
  --query 'DBClusters[0].DBClusterGroupUpgradeWave'
```

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

Call `ModifyDBCluster` with `DBClusterIdentifier` and `DBClusterGroupUpgradeWave`. Read the wave back from `DBClusterGroupUpgradeWave` in `DescribeDBClusters`.

------

**Note**  
You must specify a wave number from 1 to 10.

## Upgrading a group
<a name="databaseclustergroups-upgrading-a-group-in-waves"></a>

The following procedure upgrades every member cluster wave by wave and confirms routing to each member cluster as it finishes.

**Before you begin**
+ Check the conditions in [How a wave upgrade works](#databaseclustergroups-upgrades-how). For a check of the member clusters' settings, see [Auditing access and member cluster configuration](databaseclustergroups-auditing.md).
+ If the target version needs a new parameter group family, prepare one parameter group with the same values for every member cluster. For more information, see [Parameter groups for Amazon Aurora](USER_WorkingWithParamGroups.md).
+ Export the mappings, as described in [Exporting the mappings before and after a change](databaseclustergroups-changing-mappings.md#databaseclustergroups-export-mappings).

**To upgrade a group**

1. With the AWS CLI, take a group snapshot, as described in [Creating a snapshot of a database cluster group for Aurora](databaseclustergroups-backups.md#databaseclustergroups-taking-a-group-snapshot). Check that its `SnapshotDatabaseTime` is later than your last mapping change.

1. With the AWS CLI, choose a valid minor target version, as you do for a single cluster. For the versions and how to list valid upgrade targets, see [Database engine updates for Amazon Aurora MySQL](AuroraMySQL.Updates.md).

1. With the AWS CLI, check each member cluster's wave against your plan, and change any that differ, as described in [Assigning upgrade waves](#databaseclustergroups-upgrades-waves).

1. With the AWS CLI or the Amazon RDS API, request the group upgrade with the target version, as shown in the first set of tabs after this procedure. Without `--apply-immediately`, the upgrade starts in the group's maintenance window, and `PendingModifiedValues` shows the target until then.

1. With the AWS CLI, follow progress with the status of the group and of each member cluster, each member cluster's `EngineVersion`, and the group's `MinEngineVersion` and `MaxEngineVersion`. Each member cluster also emits Amazon RDS events when its upgrade starts and when it completes. For events, see [Amazon RDS events for database cluster groups for Aurora](databaseclustergroups-group-events.md).

   ```bash
   aws rds describe-db-clusters --region {{REGION}} --db-cluster-identifier {{CLUSTER_IDENTIFIER}} \
     --query 'DBClusters[0].[Status,EngineVersion]' --output text
   ```

1. At the routing endpoint, as each member cluster reaches the target version and reads `available`, check it without waiting for the last wave. Confirm that it's listed in `dbclustergroup_sys.member_cluster_mappings`, that a pin to it returns its new version, and that one routed read per mapping on it returns rows. The pin statement follows the second set of tabs after this procedure.

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

```bash
aws rds modify-db-cluster-group --region {{REGION}} --db-cluster-group-identifier {{GROUP_IDENTIFIER}} \
  --engine-version {{TARGET_ENGINE_VERSION}} --apply-immediately
```

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

Call `ModifyDBClusterGroup` with `DBClusterGroupIdentifier` and `EngineVersion`. To start the upgrade now instead of in the maintenance window, also pass `ApplyImmediately`.

------

**Step 6.** At the routing endpoint, pin a session to the upgraded member cluster, read its host name and version, and clear the pin.

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

The upgrade is complete when the group reads `available` with `PendingModifiedValues` empty and every member cluster is on the target version. If a member cluster didn't reach the target version, request the group upgrade again, as described in [How a wave upgrade works](#databaseclustergroups-upgrades-how).

**Reading the progress of an upgrade**

The group's `MinEngineVersion` and `MaxEngineVersion` in `DescribeDBClusterGroups` are the lowest and the highest version strings that the member clusters run. When they're equal, every member cluster runs the same version. During a group upgrade, they change as each wave completes. If they differ, read each member cluster's `EngineVersion` with `DescribeDBClusters`.

The upgrade begins at the start of the maintenance window. To follow it, check the status of the group with `DescribeDBClusterGroups` and of each member cluster with `DescribeDBClusters`. The Amazon RDS events that each member cluster emits during its upgrade describe direct connections to it only. A message that says the cluster remains online, and the counts of preserved and dropped connections in the completion event, don't include routed sessions. The upgrade closes routed sessions, as described in [How a wave upgrade works](#databaseclustergroups-upgrades-how).

**Maintenance window and pending maintenance**

A group has its own preferred maintenance window. A group upgrade that you stage runs in that window, not in each member cluster's window. To set it, call `ModifyDBClusterGroup` with `--preferred-maintenance-window`, in the format that Aurora uses, for example `wed:04:52-wed:05:22`, and read it back from `PreferredMaintenanceWindow` in `DescribeDBClusterGroups`. For the group settings, see [Changing group settings](databaseclustergroups-group-lifecycle.md#databaseclustergroups-group-lifecycle-modify).

To apply a pending engine patch or operating system update in the group's maintenance window, call `ApplyPendingMaintenanceAction` with the group's ARN in `--resource-identifier`, the action in `--apply-action`, and `next-maintenance` in `--opt-in-type`. The ARN is the `DBClusterGroupArn` value from `DescribeDBClusterGroups`. The group identifier isn't accepted, and fails with `InvalidParameterValue`. The group applies the latest available version for each member cluster, even when the member clusters run different versions. For the maintenance model, see [Maintaining an Amazon Aurora DB cluster](USER_UpgradeDBInstance.Maintenance.md).

**To apply pending maintenance 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 **Maintenance & backups** tab, under **Pending maintenance**, select the action. You can apply **Engine patch** and **OS upgrade** actions to a group.

1. Choose whether to apply the action now or in the next maintenance window.

1. Confirm the action. The group applies an engine patch to the member clusters one wave at a time.

## Major version upgrades
<a name="databaseclustergroups-upgrades-major"></a>

A group upgrade doesn't change the major version. Upgrade one member cluster at a time with the existing Aurora operations, as you upgrade a standalone Aurora DB cluster, while the other member clusters keep serving traffic. For the procedures, see [Upgrading the major version of an Amazon Aurora MySQL DB cluster](AuroraMySQL.Updates.MajorVersionUpgrade.md). After each member cluster, check its `EngineVersion` with `DescribeDBClusters` before you start the next one. During the transition, a group can contain at most two major engine versions, and the group rejects a group upgrade request because the member clusters don't share a major version. The routing layer reports the MySQL version of the group's `MinEngineVersion`, for example `8.4.900` for `8.4.mysql_aurora.8.4.900`, in the connection handshake and from `VERSION()` and `@@version`. You don't run an operation to update it.