Perform Aiven for PostgreSQL® switchback to the primary region Limited availability
Shift your workloads back to the primary region, where your service was hosted originally before switching over to the recovery region.
Prerequisites
- CRDR switchover completed
- One of the following tools for operating CRDR:
Switch back
- CLI
- API
- Terraform
Run avn service update to promote the primary service back to active:
avn service update PRIMARY_SERVICE_NAME \
--disaster-recovery-role active
Replace PRIMARY_SERVICE_NAME with the name of the primary service, for example,
pg-demo.
Verify the switchback by checking both services:
-
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": "active"
} -
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": "passive"
}
Call the ServiceUpdate endpoint
to change the disaster_recovery_role of the primary service to active:
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": "active"}'
Replace the following:
PROJECT_NAME, for examplecrdr-testPRIMARY_SERVICE_NAME, for examplepg-demoBEARER_TOKEN
After sending the request, verify the status of each service:
-
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": "active"
} -
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": "passive"
}
The Terraform provider manages the disaster_recovery integration as a static topology
declaration. All integration fields are immutable, so a switchback requires destroying the
switched integration and restoring the original one. This approach has a window during
which the DR integration is offline. For a lower-risk switchback, use the Aiven CLI or
API instead.
To use Terraform:
-
Remove the switched disaster recovery integration from Terraform state.
terraform destroy -target=aiven_service_integration.disaster_recovery_switched -
Restore the original integration with the primary service as the source.
resource "aiven_service_integration" "disaster_recovery" {
project = var.project_name
integration_type = "disaster_recovery"
source_service_name = aiven_postgresql.primary.service_name
destination_service_name = aiven_postgresql.recovery.service_name
} -
Apply the restored configuration:
terraform apply
After the switchback completes, your primary service is Active, and the recovery service is Passive, which means the primary service is in control over your workloads.
Related pages