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 placed 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 target availability zone for 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--folder-nameor--folder-id.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 describing your infrastructure and edit the fragment with your database:
resource "yandex_ydb_database_dedicated" "<DB_name>" { ... subnet_ids = [<subnet_IDs>] ... }Under
subnet_ids, list the subnet IDs in theru-central1-a,ru-central1-b, andru-central1-davailability 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 validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou 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
yesand press Enter to confirm the changes.
-
-
Migrating in Yandex Data Transfer
If you are using a transfer of the Replication or Snapshot and increment type with your database as an endpoint, restart the transfer using one of the 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.