Perform Aiven for PostgreSQL® failback to the primary region Limited availability
Shift your workloads back to the primary region, where your service was hosted originally before failing over to the recovery region. Restore your CRDR setup.
Prerequisites
- CRDR failover completed
- One of the following tools for operating CRDR:
Revert to the primary region
Initiate a revert process 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 Service recovery cycle wizard:
-
Click Restore primary service.
Wait until the status of your primary service changes from Rebuilding to Passive. This recreates your primary service in the primary region.
-
Click Promote primary service.
Wait until the status of the primary service changes from Rebuilding to Active and the status of the recovery service changes from Rebalancing to Passive. This switches traffic and replication direction back to the recreated primary service, restoring your CRDR setup to its original configuration.
-
Click Close.
-
-
Restore the primary service by running avn service update:
avn service update PRIMARY_SERVICE_NAME \
--disaster-recovery-role passiveReplace
PRIMARY_SERVICE_NAME
with the name of the primary service, for example,pg-demo
. -
Promote the primary service to active by running avn byoc update:
avn service update PRIMARY_SERVICE_NAME \
--disaster-recovery-role activeReplace
PRIMARY_SERVICE_NAME
with the name of the primary service, for example,pg-demo
.
-
Trigger the recreation of the primary service by calling the ServiceUpdate endpoint to change the
disaster_recovery_role
of the primary service topassive
: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": "passive"}'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": "REBUILDING",
"disaster_recovery_role": "passive"
} -
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"
}
-
Promote the primary service as active by calling the ServiceUpdte endpoint to change
disaster_recovery_role
of the primary service toactive
: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 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": "RUNNING",
"disaster_recovery_role": "active"
} -
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": "passive"
}
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 get back to the original primary-recovery setup:
-
Ensure both services exist and are healthy.
resource "aiven_postgresql" "primary" {
project = var.project_name
service_name = var.primary_service_name
plan = var.service_plan
cloud_name = var.primary_cloud_region
}
resource "aiven_postgresql" "recovery" {
project = var.project_name
service_name = var.recovery_service_name
plan = var.service_plan
cloud_name = var.recovery_cloud_region
}If the services were removed from the Terraform state during the disaster, re-import them:
terraform import aiven_postgresql.primary PROJECT_NAME/PRIMARY_SERVICE_NAME
terraform import aiven_postgresql.recovery PROJECT_NAME/RECOVERY_SERVICE_NAME -
Re-establish CRDR with the original primary as active:
resource "aiven_service_integration" "disaster_recovery_restored" {
project = var.project_name
integration_type = "disaster_recovery"
source_service_name = aiven_postgresql.primary.service_name # Original primary back to active
destination_service_name = aiven_postgresql.recovery.service_name # Back to passive role
depends_on = [
aiven_postgresql.primary,
aiven_postgresql.recovery
]
} -
Apply to restore the original CRDR setup:
terraform apply
-
Verify the failback:
terraform output disaster_recovery_status
Related pages