AlloyDB for PostgreSQL offers regional and zonal instance types. To help ensure high availability (HA), every regional AlloyDB primary
instance has both an active node and a standby node, located in two different
zones. If the active node becomes unavailable for any reason, then
AlloyDB automatically promotes the standby node to become the new
active node.

You can test this automatic HA feature by using *fault injection* to abruptly
force your primary instance's active node offline. AlloyDB then
activates the emergency HA procedure that checks the primary instance's health
and then reassigns the standby node into the active-node role.

Fault injection also initiates a long-running operation that brings the former
active node back online after a brief interval. That node becomes the new
standby node of the primary instance.

For a faster method of swapping the active and standby roles of your primary
instance's nodes, see [Fail over a primary instance
manually](https://docs.cloud.google.com/alloydb/docs/instance-primary-secondary-failover).


## Before you begin

- The Google Cloud project you are using must have been [enabled to access AlloyDB](https://docs.cloud.google.com/alloydb/docs/quickstart/create-and-connect.md.txt#before-you-begin).
- You must have one of these IAM roles in the Google Cloud project you are using:
  - `roles/alloydb.admin` (the AlloyDB Admin predefined IAM role)
  - `roles/owner` (the Owner basic IAM role)
  - `roles/editor` (the Editor basic IAM role)

  If you don't have any of these roles, contact your Organization Administrator to request
  access.

<br />

## Simulate an outage with a fault injection

> [!NOTE]
> **Note:** This procedure does not apply to [basic
> instances](https://docs.cloud.google.com/alloydb/docs/basic-instance), which do not have a standby node to fail over to.

To test your primary instance's HA resiliency by abruptly shutting down its
active node, use the [`gcloud alloydb instances
inject-fault`](https://docs.cloud.google.com/sdk/gcloud/reference/alloydb/instances/inject-fault) command.
After a long-running operation completes, AlloyDB reinstates the
node.

    gcloud alloydb instances inject-fault INSTANCE_ID \
        --fault-type=stop-vm \
        --region=REGION_ID \
        --cluster=CLUSTER_ID \
        --project=PROJECT_ID

- `INSTANCE_ID`: The ID of the instance.
- `REGION_ID`: The region where the instance is placed.
- `CLUSTER_ID`: The ID of the cluster where the instance is placed.
- `PROJECT_ID`: The ID of the project where the cluster is placed.