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 yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through 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 don't have Terraform, 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, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
-
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.