Set up cross-region disaster recovery in Aiven for PostgreSQL® Limited availability
Enable cross-region disaster recovery (CRDR) in Aiven for PostgreSQL® by creating a recovery service, which takes over from a primary service in case of a region outage.
Prerequisites
- Aiven for PostgreSQL service on at least a Startup plan - see limitations
- One of the following tools for operating CRDR:
Set up a recovery service
Create a CRDR setup 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 Create recovery service.
- In Create recovery service wizard:
- Provide a service name.
- Select a cloud region.
- Click Create recovery service.
Throughout the process of creating the recovery service, the recovery service is in the Rebuilding state. As soon as the recovery service is ready, its status changes to Passive, which means your CRDR setup is up and running.
Run avn service create:
avn service create RECOVERY_SERVICE_NAME \
--service-type pg \
--plan SERVICE_PLAN \
--cloud CLOUD_PROVIDER_REGION \
--disaster-recovery-copy-for PRIMARY_SERVICE_NAME
Replace the following:
RECOVERY_SERVICE_NAMEwith the name of the recovery service, for example,pg-demo-recoverySERVICE_PLANwith the plan to use for the recovery service, for example,startup-4CLOUD_PROVIDER_REGIONwith the cloud region where to host the recovery service, for example,google-europe-west-4PRIMARY_SERVICE_NAMEwith the name of the primary service, for example,pg-demo
Call the
ServiceCreate endpoint to
create a recovery service and enable the disaster_recovery service integration between
the recovery service and the primary service, for example:
curl --request POST \
--url https://api.aiven.io/v1/project/PROJECT_NAME/service \
-H 'accept: application/json, text/plain, */*' \
-H 'Authorization: Bearer BEARER_TOKEN' \
-H 'content-type: application/json' \
--data-raw '{
"service_name": "RECOVERY_SERVICE_NAME",
"cloud": "CLOUD_PROVIDER_REGION",
"plan": "SERVICE_PLAN",
"service_type": "SERVICE_TYPE",
"disk_space_mb": DISK_SIZE,
"service_integrations": [
{
"integration_type": "disaster_recovery",
"source_service": "PRIMARY_SERVICE_NAME",
"user_config": {}
}
]
}'
Replace the following placeholders with your values:
PROJECT_NAME, for examplecrdr-testBEARER_TOKENRECOVERY_SERVICE_NAME, for examplepg-dr-testCLOUD_PROVIDER_REGION, for examplegoogle-europe-west10SERVICE_PLAN, for examplestartup-4SERVICE_TYPE, for examplepgDISK_SIZEin MiB, for example81920PRIMARY_SERVICE_NAME, for examplepg-primary-test
After sending the request, you can check the CRDR status on each of the CRDR peer services:
-
Primary service status
avn service get PRIMARY_SERVICE_NAME
--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 RECOVERY_SERVICE_NAME
--project PROJECT_NAME
--json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}'Expect the following output:
{
"state": "REBUILDING",
"disaster_recovery_role": "passive"
}
-
Use the
aiven_service_integrationresource to create the disaster recovery integration between your primary service and the recovery service. Setintegration_typetodisaster_recovery.# Primary PostgreSQL service
resource "aiven_postgresql" "primary" {
project = var.project_name
service_name = var.primary_service_name
plan = var.service_plan
cloud_name = var.primary_cloud_region
}
# Recovery PostgreSQL service
resource "aiven_postgresql" "recovery" {
project = var.project_name
service_name = var.recovery_service_name
plan = var.service_plan
cloud_name = var.recovery_cloud_region
}
# Disaster recovery integration
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
depends_on = [
aiven_postgresql.primary,
aiven_postgresql.recovery
]
} -
Apply the configuration:
terraform apply -
Monitor the setup status:
terraform show aiven_service_integration.disaster_recovery
Related pages