Perform Aiven for PostgreSQL® failover to the recovery region Limited availability
Move your workload to another region for disaster recovery or testing purposes.
A failover allows you to respond to a region outage or simulate a disaster and test the resilience of your infrastructure.
Prerequisites
- CRDR setup up and running
- One of the following tools for operating CRDR:
Perform a failover
Initiate a failover using a tool of your choice:
- Console
- CLI
- API
- Terraform
- Log in to the Aiven Console, and go to your primary Aiven for PostgreSQL service.
- Click Disaster recovery in the sidebar.
- On the Cross-region disaster recovery page, click Manage.
- In the Service recovery cycle wizard, click Initiate failover > Close.
When the failover process is completed, your primary service is Failed, and the recovery service is Active, which means the recovery service is in control over your workloads.
Run avn service update:
avn service update PRIMARY_SERVICE_NAME \
--disaster-recovery-role failed
Replace PRIMARY_SERVICE_NAME
with the name of the primary service, for example, pg-demo
.
Call the ServiceUpdte endpoint
to change the disaster_recovery_role
of the primary service to failed
:
curl --request PUT \
--url https://api.aiven.io/v1/project/PROJECT_NAME/service/PRIMARY_SERVICE_NAME \
-H 'Authorization: Bearer BEARER_TOKEN' \
-H 'content-type: application/json' \
--data '{"disaster_recovery_role": "failed"}'
Replace the following placeholders with meaningful data:
PROJECT_NAME
, for examplecrdr-test
PRIMARY_SERVICE_NAME
, for examplepg-primary-test
BEARER_TOKEN
After sending the request, you can check the CRDR status on each of the CRDR peer services:
-
Primary service status
avn service get pg-primary
--project $PROJECT_NAME
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "POWEROFF",
"disaster_recovery_role": "failed"
} -
Recovery service status
avn service get pg-primary-dr
--project $PROJECT_NAME
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "RUNNING",
"disaster_recovery_role": "active"
}
The
aiven_service_integration
resource with the disaster_recovery
type manages the active-passive relationship between
services. CRDR operations are performed by manipulating this integration.
To trigger failover and promote the recovery service to active:
-
Remove the existing disaster recovery integration from the Terraform state.
terraform state rm aiven_service_integration.disaster_recovery
-
If primary service is completely unreachable, remove it from the Terraform state.
terraform state rm aiven_postgresql.primary
The recovery service is now promoted to active and can handle traffic.
Related pages