

# ALTER DBCLUSTERGROUP CUTOVER JOB

Starts the cutover, the final step of a move, for a data movement job in a database cluster group for Aurora. Use it to cut over a job that you started with `MANUAL_CUTOVER = 1`, or to cut over an automatic job earlier.

## Description
<a name="databaseclustergroups-sql-switch-job-description"></a>

At the cutover, the job fences the moving objects on the source and ends every transaction that is open on them. Each such transaction rolls back, and the session receives an error or loses its connection, so retry it. The last changes then apply, and the job updates the collocation's data mappings to name the target member cluster. The job then drops the source copy. Use this statement to choose when the cutover happens. A job accepts it while the job is in the CDC Replication phase and replication lag is at or below the bound that you set. For the error codes, see [Moving data between member clusters](databaseclustergroups-data-movement.md).

A data movement job that you started with `MANUAL_CUTOVER = 1` will not cut over until you run this command. You can also run this statement on a job that cuts over automatically if you want to cut over with replication lag greater than 1 second.

## Syntax
<a name="databaseclustergroups-sql-switch-job-syntax"></a>

The syntax is as follows.

```sql
ALTER DBCLUSTERGROUP CUTOVER JOB '{{job_id}}' [MAX_REPLICATION_LAG_SECONDS = {{seconds}}];
```

## Parameters and options
<a name="databaseclustergroups-sql-switch-job-parameters"></a>

The statement takes the following parameters.

{{job\_id}}  
The job ID from the move result or from `move_info`, as a string literal in single quotes.

MAX\_REPLICATION\_LAG\_SECONDS = {{seconds}}  
Optional. The cutover starts only when replication lag is below this bound. The range is 1 to 300 seconds, and the default is 10 seconds.

## Where it runs and required privileges
<a name="databaseclustergroups-sql-switch-job-privileges"></a>

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`. For the privileges for database cluster groups for Aurora, see [Privileges](databaseclustergroups-sql-reference.md#databaseclustergroups-sql-privileges).

## Usage notes
<a name="databaseclustergroups-sql-switch-job-usage"></a>

Keep the following in mind when you use the statement.
+ Before you start the cutover, read the job's replication lag in [Reading move status](databaseclustergroups-sql-move-info.md). The cutover starts only while replication lag is below the bound, so the job refuses a statement that you send while lag is higher. Read the lag again, and send the statement when it is lower. For the job events, see [Reading move status](databaseclustergroups-running-a-move.md#databaseclustergroups-move-monitoring).
+ The job accepts the statement only in the CDC Replication phase (`Cdc` in the `phase` column of `move_info`), after the Seeding phase completes.
+ During the cutover, the job refuses reads and writes to the moving objects and doesn't hold them, so your application must retry the query. For the error codes, see [Moving data between member clusters](databaseclustergroups-data-movement.md).

**Important**  
A large `MAX_REPLICATION_LAG_SECONDS` value can lengthen the time that reads and writes to the moving objects are rejected.

## Examples
<a name="databaseclustergroups-sql-switch-job-examples"></a>

The following example starts the cutover of a job when replication lag is below 30 seconds.

```sql
ALTER DBCLUSTERGROUP CUTOVER JOB '4a6f1c2e-7d3b-4c1a-9e2f-5b8d0c6a1f30' MAX_REPLICATION_LAG_SECONDS = 30;
```

The following example cuts over a job that you started without `MANUAL_CUTOVER = 1`, when replication lag is below 5 seconds:

```sql
ALTER DBCLUSTERGROUP CUTOVER JOB '4a6f1c2e-7d3b-4c1a-9e2f-5b8d0c6a1f30' MAX_REPLICATION_LAG_SECONDS = 5;
```

## Errors
<a name="databaseclustergroups-sql-switch-job-errors"></a>

The statement can return the following errors. For all data movement errors, see [Data movement errors](databaseclustergroups-errors-movement.md).


| 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. | 
| 1179 (25000) | You are not allowed to execute this command in a transaction | The statement ran inside a transaction. Run it outside a transaction. | 
| 1221 (HY000) | Cannot cut over a job in the {{phase}} phase. The job must be in the CDC phase to perform cutover | The job isn't in the CDC Replication phase yet. {{phase}} is in capitals. | 
| 1221 (HY000) | Replication lag ({{n}} seconds) is not below the maximum replication lag threshold ({{n}} seconds) | Replication lag is at or above the bound. Read the lag in move\_info, and run the statement again when it is lower. | 
| 1221 (HY000) | Replication lag has not been reported for this job yet; retry once replication progress is available | The job hasn't reported any lag yet. | 
| 1525 (HY000) | Incorrect MAX\_REPLICATION\_LAG\_SECONDS value: '{{value}}'; it must be between 1 and 300 seconds | The bound is outside 1 to 300. | 
| 1221 (HY000) | Cannot cut over a job in the {{state}} state | The job has ended. {{state}} is in capitals, for example COMPLETED. | 
| 1221 (HY000) | Cannot cut over a job with a cancel in progress | Someone canceled the job. | 
| 1525 (HY000) | Incorrect job ID value: '{{value}}' | The job ID isn't a valid ID. | 
| 1305 (42000) | MOVE JOB '{{job\_id}}' does not exist | No job has this ID. | 

## Related statements
<a name="databaseclustergroups-sql-switch-job-related"></a>

For more information, see the following:
+ [ALTER DBCLUSTERGROUP MOVE COLLOCATION](databaseclustergroups-sql-move-collocation.md)
+ [ALTER DBCLUSTERGROUP CANCEL JOB](databaseclustergroups-sql-cancel-job.md)
+ [Reading move status](databaseclustergroups-sql-move-info.md)