This page describes how to perform a switchover to a peer Autonomous AI Database in
Google Cloud. You can perform a switchover through both
Google Cloud and OCI.

If the Primary Autonomous AI Database is down, you can perform a switchover from
the peer (Standby) database.

## Before you begin

Ensure that you have the following roles and permissions required to perform a
switchover:

- `roles/autonomousDatabaseAdmin`

## Perform a Switchover

To switchover to a peer database, do the following:

### Console

1. Go to the **Autonomous AI Database** page.

   [Go to Autonomous AI Database](https://console.cloud.google.com/oracle/autonomous-databases/)
2. Click the name of the primary Autonomous AI Database on which you want to
   perform a switchover operation.

3. On the **Autonomous AI Database details** page, click the
   **Disaster Recovery** tab.

4. In the **Peer database** section, for the peer database that you want to
   switchover to, click **View actions** ,
   and then click **Switchover**.

5. In the **Confirm switchover to peer** dialog, do the following:

   1. If your primary database is not automatically detected, select the region of your primary database.
   2. Enter the ID of your peer database.
   3. Click **Confirm**.

On the **Disaster recovery** tab, in the **Peer database** section, the
**Status** field shows you the progress of the switchover operation.
After the switchover is complete, the peer database becomes the "Primary"
and its **Status** field shows "Available". Whereas, the former Primary
Autonomous AI Database becomes the "Standby".

If you initiated the switchover in the OCI console, you can still see the
progress of the switchover in the Google Cloud console.

### gcloud

To perform a switchover to a cross-region peer, run the `gcloud oracle-database autonomous-databases switchover`
command.

    gcloud oracle-database autonomous-databases switchover DATABASE_ID
    --project=PROJECT_ID
    --location=REGION
    --peer-autonomous-database=projects/PROJECT_ID/locations/REGION/autonomousDatabases/PEER_DATABASE_ID

Replace the following:

- <var translate="no">DATABASE_ID</var>: the ID of your database
- <var translate="no">PROJECT_ID</var>: the ID of your Google Cloud project
- <var translate="no">REGION</var>: the region where your database is located
- <var translate="no">PEER_DATABASE_ID</var>: the ID of your peer database

To perform a controlled switchover to a local standby peer database, run the following command:

    gcloud oracle-database autonomous-databases switchover DATABASE_ID
    --project=PROJECT_ID
    --location=REGION

Replace the following:

- <var translate="no">DATABASE_ID</var>: the ID of your database
- <var translate="no">PROJECT_ID</var>: the ID of your Google Cloud project
- <var translate="no">REGION</var>: the region where your database is located

### API

To perform a switchover to a cross-region peer, run the following `curl`
command:

```
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://oracledatabase.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/autonomousDatabases/DATABASE_ID:switchover" \
-d \
'{
  "peerAutonomousDatabase": "projects/PROJECT_ID/locations/REGION/autonomousDatabases/PEER_DATABASE_ID"
}'
```

Replace the following:

- <var translate="no">PROJECT_ID</var>: the ID of your Google Cloud project
- <var translate="no">REGION</var>: the region where your database is located
- <var translate="no">DATABASE_ID</var>: the ID of your database
- <var translate="no">PEER_DATABASE_ID</var>: the ID of your peer database

To perform a controlled switchover to a local standby peer database, run the
following `curl` command:

```
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://oracledatabase.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/autonomousDatabases/DATABASE_ID:switchover"
```

Replace the following:

- <var translate="no">PROJECT_ID</var>: the ID of your Google Cloud project
- <var translate="no">REGION</var>: the region where your database is located
- <var translate="no">DATABASE_ID</var>: the ID of your database

## What's next

- [View peer database details](https://docs.cloud.google.com/oracle/database/docs/view-peer-databases.md.txt).
- [Create a peer database](https://docs.cloud.google.com/oracle/database/docs/create-peer-database.md.txt).