Migrating a YDB database to a different availability zone
Migration to another availability only makes sense for a YDB dedicated database. Serverless databases are not migrated between availability zones.
A dedicated database is hosted in multiple availability zones of the central Russia ru-central1
region. You can replace one zone with another. To do this:
-
Create a subnet in the availability zone to which you are migrating your database.
-
Move the YDB database to a new set of subnets:
Yandex Cloud CLITerraformIf you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the
yc config set folder-id <folder_ID>
command. You can also set a different folder for any specific command using the--folder-name
or--folder-id
parameter.Run this command:
yc ydb database update <DB_name> \ --subnet-id <subnet_ID_in_ru-central1-a_availability_zone> \ --subnet-id <subnet_ID_in_ru-central1-b_availability_zone> \ --subnet-id <subnet_ID_in_ru-central1-d_availability_zone>
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file containing the infrastructure plan and edit the fragment with the DB description:
resource "yandex_ydb_database_dedicated" "<DB_name>" { ... subnet_ids = [<subnet_IDs>] ... }
In the
subnet_ids
parameter, list the subnet IDs in theru-central1-a
,ru-central1-b
, andru-central1-d
availability zones, separated by commas. -
Apply the changes:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm the changes.
-
-
Migrating to Yandex Data Transfer
If are using a transfer of the Replication or Snapshot and increment type and your database serves as an endpoint, restart the transfer using one of two methods after changing subnets in the database:
To restart a transfer, choose one of the two methods:
- Deactivate the transfer and wait for its status to change to Stopped. Next, reactivate the transfer and wait for its status to change to Replicating.
- Update any setting for the transfer or endpoint.
For more information, see Migrating a Data Transfer transfer and endpoints to a different availability zone.