Perform Aiven for PostgreSQL® switchover to the recovery region Limited availability
Perform a planned promotion of your recovery service while the primary service is healthy.
Switch over to your Aiven for PostgreSQL® recovery service for planned maintenance, simulating a disaster, or testing the resilience of your infrastructure.
Prerequisites
- CRDR setup up and running
- One of the following tools for operating CRDR:
Switch over
- CLI
- API
- Terraform
Run avn service update to promote the recovery service to active:
avn service update RECOVERY_SERVICE_NAME \
--disaster-recovery-role active
Replace RECOVERY_SERVICE_NAME with the name of the recovery service, for example,
pg-demo-recovery.
Verify the switchover by checking both services:
-
Recovery service status:
avn service get RECOVERY_SERVICE_NAME \
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "RUNNING",
"disaster_recovery_role": "active"
} -
Primary service status:
avn service get PRIMARY_SERVICE_NAME \
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "RUNNING",
"disaster_recovery_role": "passive"
}
Call the ServiceUpdate endpoint
to change the disaster_recovery_role of the recovery service to active:
curl --request PUT \
--url https://api.aiven.io/v1/project/PROJECT_NAME/service/RECOVERY_SERVICE_NAME \
-H 'Authorization: Bearer BEARER_TOKEN' \
-H 'content-type: application/json' \
--data '{"disaster_recovery_role": "active"}'
Replace the following:
PROJECT_NAME, for examplecrdr-testRECOVERY_SERVICE_NAME, for examplepg-demo-recoveryBEARER_TOKEN
After sending the request, verify the status of each service:
-
Recovery service status:
avn service get RECOVERY_SERVICE_NAME \
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "RUNNING",
"disaster_recovery_role": "active"
} -
Primary service status:
avn service get PRIMARY_SERVICE_NAME \
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "RUNNING",
"disaster_recovery_role": "passive"
}
The Terraform provider manages the disaster_recovery integration as a static topology
declaration. All integration fields are immutable, so a switchover requires destroying the
existing integration and creating a new one with the source and destination reversed.
This approach has a window during which the DR integration is offline. For a
lower-risk switchover, use the Aiven CLI or API instead.
To use Terraform:
-
Remove the existing disaster recovery integration from Terraform state.
terraform destroy -target=aiven_service_integration.disaster_recovery -
Create an integration with the recovery service as the source.
resource "aiven_service_integration" "disaster_recovery_switched" {
project = var.project_name
integration_type = "disaster_recovery"
source_service_name = aiven_postgresql.recovery.service_name
destination_service_name = aiven_postgresql.primary.service_name
} -
Apply the new configuration:
terraform apply
After the switchover completes, your primary service is Passive, and the recovery service is Active, which means the recovery service is in control over your workloads.
Related pages