This page describes how to perform a failover operation for an Autonomous AI Database
in Google Cloud.

For your Autonomous AI Database, Oracle Database@Google Cloud lets you failover to a standby
peer database.

> [!CAUTION]
> **Caution:** If your primary database is accessible, we recommend that you [perform a switchover](https://docs.cloud.google.com/oracle/database/docs/perform-switchover.md.txt). Perform a failover only in the event of a disaster when your primary database becomes inaccessible, because a failover operation is irreversible, and might result in data loss and disconnection of all clients.

## Before you begin

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

- `roles/autonomousDatabaseAdmin`

## Perform a failover

To failover to a standby peer database, do the following:

### Console

- In the event of a disaster, if your primary database is inaccessible,
  follow these steps:

  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 standby peer for which you want
     to perform the failover operation.

  3. On the **Autonomous AI Database details** page, click **Failover**.

  4. In the **Confirm failover 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 primary database.
     3. Click **Confirm**.
- If your primary database is accessible, follow these steps:

  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 database for which you want to perform
     the failover operation.

  3. On the **Autonomous AI Database details** page, select the **Disaster recovery**
     tab.

  4. For the peer database to which you want to failover, click
     **View actions** ,
     and then click **Failover**.

  5. In the **Confirm failover to peer** dialog,
     enter the ID of your primary database.

  6. Click **Confirm**.

After the failover is complete, the peer database becomes the "Primary"
and its **Status** field shows "Available".

### gcloud

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

    gcloud oracle-database autonomous-databases failover PEER_DATABASE_ID
    --project=PROJECT_ID
    --location=PEER_REGION
    --peer-autonomous-database=projects/PROJECT_ID/locations/PRIMARY_REGION/autonomousDatabases/PRIMARY_DATABASE_ID

Replace the following:

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

To perform a manual failover to a local standby peer database, run the following command:

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

Replace the following:

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

### API

To perform a failover operation, 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/PEER_REGION/autonomousDatabases/PEER_DATABASE_ID:failover" \
-d \
'{
  "peer_autonomous_database": "projects/PROJECT_ID/locations/PRIMARY_REGION/autonomousDatabases/PRIMARY_DATABASE_ID"
}'
```

Replace the following:

- <var translate="no">PROJECT_ID</var>: the ID of your Google Cloud project which contains your primary database
- <var translate="no">PEER_REGION</var>: the region where your peer database is located
- <var translate="no">PEER_DATABASE_ID</var>: the ID of your peer database
- <var translate="no">PRIMARY_REGION</var>: the region where your primary database is located
- <var translate="no">PRIMARY_DATABASE_ID</var>: the ID of your primary database

To perform a manual failover 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:failover"
```

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 primary database is located
- <var translate="no">DATABASE_ID</var>: the ID of your primary database

## What's next

- [Perform a switchover](https://docs.cloud.google.com/oracle/database/docs/perform-switchover.md.txt).
- [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).