Managing YDB databases
In Managed Service for YDB, you can create a database in two modes: serverless and dedicated, i.e., with dedicated servers.
You can use the management console or Yandex Cloud CLI to:
- Create and update the parameters of a serverless database.
- Create and update the parameters of a dedicated database.
- View a list of databases.
- Delete a database.
Creating and updating the parameters of a serverless database
Creating a serverless database
-
In the management console
, select the folder for your database. -
Go to Managed Service for YDB.
-
Click Create a database.
-
Enter a Name for your database. The naming requirements are as follows:
- Length: between 3 and 63 characters.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Under Database type, select
Serverless. -
Under Load type, select one of these options:
OLTPOLAP (Analytics β)
-
The default values we set will help you get started in the most efficient way. You can change them right away or later, if required. For more information about the database settings, see Serverless and dedicated modes.
-
Click Create a database.
Wait for the database status to change to Running.
If 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.
-
View the description of the Yandex Cloud CLI command for creating a database:
yc ydb database create --help -
Run this command:
yc ydb database create <DB_name> --serverlessResult:
id: etne027gi9aa******** folder_id: b1gmit33ngp3******** created_at: "2022-12-13T09:17:06Z" name: svlbd status: PROVISIONING endpoint: grpcs://ydb.serverless.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etne027gi9aa******** serverless_database: storage_size_limit: "53687091200" location_id: ru-central1 backup_config: backup_settings: - name: daily backup_schedule: daily_backup_schedule: execute_time: hours: 17 backup_time_to_live: 604800s type: SYSTEM document_api_endpoint: https://docapi.serverless.yandexcloud.net/ru-central1/b1gia87mbaom********/etne027gi9aa******** monitoring_config: {}
You can update any parameter later by running the update Yandex Cloud CLI command or using the management console. For more information, see Serverless database parameters.
Every serverless database is created with geographic redundancy across three availability zones.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
In the Terraform configuration file, define the properties of the serverless database you want to create:
resource "yandex_ydb_database_serverless" "database1" { name = "<DB_name>" deletion_protection = "<deletion_protection>" serverless_database { enable_throttling_rcu_limit = <throughput_capacity_limit> provisioned_rcu_limit = <throughput_capacity> storage_size_limit = <data_size> throttling_rcu_limit = <provisioned_capacity> } }Where:
name: Database name. This is a required setting.deletion_protection: Database deletion protection,trueorfalse. You cannot delete a database with this option enabled. Enabled deletion protection does not protect the database contents. The default value isfalse.enable_throttling_rcu_limit: Enable throughput capacity limit,trueorfalse. This is an optional setting. The default value isfalse.provisioned_rcu_limit: Limit on request units consumed per second. This is an optional setting. The default value is0.storage_size_limit: Data size limit in bytes. This is an optional setting. The default value is50GB.throttling_rcu_limit: Shows the request unit usage per second charged on an hourly basis according to the pricing plan. If set to 0, hourly billing is off. This is an optional setting. The default value is0.
-
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.
-
Terraform will create all the required resources. You can check the update using the management console
yc ydb database get <DB_name>
Example
Creating a serverless database protected against deletion, with the 10 RU/s throughput limit and 50 GB of data:
resource "yandex_ydb_database_serverless" "database1" { name = "test-ydb-serverless" deletion_protection = "true" serverless_database { enable_throttling_rcu_limit = false provisioned_rcu_limit = 10 storage_size_limit = 50 throttling_rcu_limit = 0 } }
To create a serverless database, use the create REST API method for the Database resource or the DatabaseService/Create gRPC API call and provide the following in the request:
- ID of the folder to host the database in the
folderIdparameter. - Database name in the
nameparameter. - Database throughput capacity in the
serverlessDatabase.throttlingRcuLimitparameter. - Database size, in bytes, in the
serverlessDatabase.storageSizeLimitparameter.
Updating serverless database parameters
- In the management console
, select the folder where you want to update the database settings. - Go to Managed Service for YDB.
- Click
in the row with the database in question and select Edit. - Configure the database:
- Change the database name, if required.
- Under Limits, specify the throughput capacity and data size.
- Under Pricing, set the provisioned throughput capacity.
- Click Update database.
If 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.
View the description of the Yandex Cloud CLI command for updating a database:
yc ydb database update --help
Serverless database parameter names start with sls-. Other parameters only apply to dedicated databases.
Examples
-
Renaming the
dbtestdatabase tomydb:yc ydb database update dbtest \ --new-name mydb -
Setting a usage limit of 100 request units per second for a serverless database named
db5:yc ydb database update db5 \ --sls-throttling-rcu 100
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and edit the fragment describing the serverless database:
resource "yandex_ydb_database_serverless" "database1" { name = "<DB_name>" deletion_protection = "<deletion_protection>" serverless_database { enable_throttling_rcu_limit = <throughput_capacity_limit> provisioned_rcu_limit = <throughput_capacity> storage_size_limit = <data_size> throttling_rcu_limit = <provisioned_capacity> } }Where:
name: Database name. This is a required setting.deletion_protection: Database deletion protection,trueorfalse. You cannot delete a database with this option enabled. Enabled deletion protection does not protect the database contents. The default value isfalse.enable_throttling_rcu_limit: Enable throughput capacity limit,trueorfalse. This is an optional setting. The default value isfalse.provisioned_rcu_limit: Limit on request units consumed per second. This is an optional setting. The default value is0.storage_size_limit: Amount of data, in GB. This is an optional setting. The default value is50.throttling_rcu_limit: Shows the request unit usage per second charged on an hourly basis according to the pricing plan. If set to 0, hourly billing is off. This is an optional setting. The default value is0.
-
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.
-
Terraform will apply the required changes to the resources. You can check the update using the management console
yc ydb database get <DB_name>
Example
Changing the provisioned throughput capacity and amount of data for the test-ydb-serverless database:
resource "yandex_ydb_database_serverless" "database1" { name = "test-ydb-serverless" deletion_protection = "true" serverless_database { enable_throttling_rcu_limit = false provisioned_rcu_limit = 10 storage_size_limit = 80 throttling_rcu_limit = 100 } }
To change the serverless database parameters, use the update REST API method for the Database resource or the DatabaseService/Update gRPC API call and specify the database ID in the databaseId request parameter.
You can get the database ID with the list of databases.
Provide the following in the request:
- ID of the folder to host the database in the
folderIdparameter. - Database name in the
nameparameter. - Database throughput capacity in the
serverlessDatabase.throttlingRcuLimitparameter. - Database size, in bytes, in the
serverlessDatabase.storageSizeLimitparameter. - Computing resource ID in the
resourcePresetIdparameter. - Network ID in the
networkIdparameter. - Storage type in the
storageConfig.storageOptions.storageTypeIdparameter. - Number of storage groups in the
storageConfig.storageOptions.groupCountparameter. - Number of database instances in the
scalePolicy.fixedScale.sizeparameter.
Creating and updating dedicated database parameters
Creating a dedicated database
-
In the management console
, select the folder for your database. -
Go to Managed Service for YDB.
-
Click Create a database.
-
Specify a Name for the database. The naming requirements are as follows:
- Length: between 3 and 63 characters.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Under Database type, select
Dedicated. -
Under Load type, select one of these options:
OLTPOLAP
-
Under Computing resources, select the type and amount of computing resources.
Warning
For reliable and stable performance, a database needs multiple slots. A database run in the production environment must have at least three slots.
-
Under Storage groups, select the disk type and number of storage groups that determines the total amount of storage.
-
Under Network, configure the network:
-
Optionally, in the Public IP addresses field, select Assign if you plan to query the database both from the Yandex Cloud network and the internet.
Warning
For Managed Service for YDB databases with external IPs, the usage of outgoing internet traffic is counted by the current pricing policy.
The charges for outgoing internet traffic generated by Managed Service for YDB usage will be offset by grants.
-
Select an existing network from the Cloud network list or create a new one:
- Click Create.
- In the window that opens, enter a Name for the new network.
- Optionally, select Create subnets. Subnets in each availability zone will be created automatically.
- Click Create network.
-
Under Subnets, select a subnet or create a new one for each availability zone:
- Click Create.
- In the window that opens, enter a Name for the new subnet.
- Optionally, enter a Description for the subnet.
- Select the availability zone from the Availability zone list.
- Set the subnet address in CIDR
format. - Click Create subnet.
-
-
Click Create a database.
Wait for the database status to change to Running.
If 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.
-
View the description of the Yandex Cloud CLI command for creating a database:
yc ydb database create --help -
Run this command:
yc ydb database create <DB_name> \ --dedicated \ --network-name <network_name> \ --storage <storage_type>,<number_of_storage_groups> \ --resource-preset <computing_resource_configuration> \Where:
--dedicated: Configuration of the database with dedicated servers.--network-name: Name of the cloud network to create the database in. You can specify thedefaultnetwork.--storage: Storage type and number of storage groups intype=<storage_type>,groups=<number_of_storage_groups>format. For thessdtype, a single storage group can store up to 100 GB of data.--resource-preset: Configuration of the node computing resources. You can find the valid values in the Configuration name column of the table in Database on dedicated resources.
Important additional parameters:
--public-ip: Public IP address assignment flag. Without it, you will not be able to connect to your database from the internet.--fixed-size INT: Number of cluster nodes,1by default. Nodes are allocated in different availability zones, so a configuration of three nodes will be geographically distributed across three availability zones.--async: Asynchronous database creation flag. Creating a dedicated database may take a while, up to a few minutes. You can set this flag to regain control as soon as the cloud gets the command to create a database.
Examples
-
Creating a single-node dedicated YDB database with the minimum configuration, named
dedband accessible from the internet:yc ydb database create dedb \ --dedicated \ --network-name default \ --storage type=ssd,groups=1 \ --resource-preset medium \ --public-ip -
Asynchronously creating a three-node dedicated YDB database with geographic redundancy, 300 GB of storage, and computing nodes with 64 GB RAM each, named
dedb3and accessible from the internet:yc ydb database create dedb3 \ --dedicated --network-name default \ --storage type=ssd,groups=3 \ --resource-preset medium-m64 \ --public-ip \ --fixed-size 3 \ --async
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
In the Terraform configuration file, define the properties of the dedicated database to create:
resource "yandex_ydb_database_dedicated" "database1" { name = "<DB_name>" network_id = "<network_ID>" subnet_ids = ["<subnet_1_ID>", "<subnet_2_ID>", "<subnet_3_ID>"] resource_preset_id = "<computing_resource_configuration>" deletion_protection = "<deletion_protection>" scale_policy { fixed_scale { size = <number_of_DB_instances> } } storage_config { group_count = <number_of_storage_groups> storage_type_id = "<storage_type>" } }Where:
name: Database name.network_id: ID of the network the database is connected to.subnet_ids: List of subnet IDs separated by commas.resource_preset_id: Configuration of the node computing resources. You can find the valid values in the Configuration name column of the table in Database on dedicated resources.deletion_protection: Database deletion protection,trueorfalse. You cannot delete a database with this option enabled. Enabled deletion protection does not protect the database contents. The default value isfalse.scale_policy: Scaling policy, wheresizeindicates the number of database instances.storage_config: Storage configuration, where:group_count: Number of storage groups.storage_type_id: Storage type. For thessdtype, a single storage group can store up to 100 GB of data.
-
Create a database:
-
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.
-
Terraform will create all the required resources. You can check the update using the management console
yc ydb database list
Example
Creating a single-node dedicated Managed Service for YDB database named test-bd with the minimum configuration and accessible from the internet:
resource "yandex_ydb_database_dedicated" "database2" { name = "test-ydb-dedicated" network_id = yandex_vpc_network.my-net.id subnet_ids = [yandex_vpc_subnet.my-subnet-a.id, yandex_vpc_subnet.my-subnet-b.id, yandex_vpc_subnet.my-subnet-d.id] resource_preset_id = "medium" deletion_protection = "true" scale_policy { fixed_scale { size = 1 } } storage_config { group_count = 1 storage_type_id = "ssd" } }
To create a dedicated database, use the create REST API method for the Database resource or the DatabaseService/Create gRPC API call and provide the following in the request:
- ID of the folder to host the database in the
folderIdparameter. - Database name in the
nameparameter. - Permission to assign public IP addresses to database nodes in the
dedicatedDatabase.assignPublicIpsparameter. - Computing resource ID in the
resourcePresetIdparameter. - Network ID in the
networkIdparameter. - Storage type in the
storageConfig.storageOptions.storageTypeIdparameter. - Number of storage groups in the
storageConfig.storageOptions.groupCountparameter. - Number of database instances in the
scalePolicy.fixedScale.sizeparameter.
Updating dedicated database parameters
- In the management console
, select the folder where you want to update the database settings. - Go to Managed Service for YDB.
- Click
in the row with the database in question and select Edit. - Configure the database:
- Change the database name, if required.
- Under Computing resources, select the type and amount of computing resources.
- Under Storage groups, select the disk type and number of storage groups that determines the total amount of storage.
- Click Update database.
If 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.
View the description of the Yandex Cloud CLI command for updating a database:
yc ydb database update --help
Dedicated database parameters have no sls- prefix.
Example
Changing the number of storage groups for a database with the SSD storage type and a single storage group:
yc ydb database update test-db \ --storage type=ssd,group=2
You cannot decrease the number of storage groups.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and edit the fragment describing your database:
resource "yandex_ydb_database_dedicated" "database2" { name = "my-first-ydb-dedicated" network_id = yandex_vpc_network.my-net.id subnet_ids = [yandex_vpc_subnet.my-subnet-a.id, yandex_vpc_subnet.my-subnet-b.id, yandex_vpc_subnet.my-subnet-d.id] resource_preset_id = "medium" deletion_protection = "true" scale_policy { fixed_scale { size = 2 } } storage_config { group_count = 1 storage_type_id = "ssd" } } -
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.
-
You can check the update using the management console
yc ydb database get <DB_name>
To change the dedicated database parameters, use the update REST API method for the Database resource or the DatabaseService/Update gRPC API call and specify the database ID in the databaseId request parameter.
You can get the database ID with the list of databases.
In the request, provide a set of parameters used when creating the dedicated database with your updated values.
To move a database to a different availability zone, follow this guide.
Viewing the list of databases
- In the management console
, select the folder to get a list of databases for. - Go to Managed Service for YDB.
If 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 list
To get a list of databases in the folder, use the list REST API method for the Database resource or the DatabaseService/List gRPC API call and provide the folder ID in the folderId request parameter.
Assigning a role for a database
You can grant access to a Managed Service for YDB database to a user, service account, or user group. To do this, assign a role for the database. To choose the one you need, learn about the existing roles.
- In the management console
, select the folder the database resides in. - Go to Managed Service for YDB.
- Click the name of the database.
- Navigate to
Access bindings and click Assign roles. - Select the group, user, or service account you want to grant access to the database to.
- Click
Add role and select the required roles. - Click Save.
If 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.
To assign a role for a database:
-
View the description of the CLI command for assigning roles:
yc ydb database add-access-binding --help -
Get a list of databases with their IDs:
yc ydb database list -
Get the ID of the user, service account, or user group you are assigning a role to.
-
Use one of these commands to assign a role:
-
To a user:
yc ydb database add-access-binding \ --id <DB_ID> \ --role <role> \ --user-account-id <user_ID> -
To a federated user:
yc ydb database add-access-binding \ --id <DB_ID> \ --role <role> \ --user-account-id <user_ID> -
To a service account:
yc ydb database add-access-binding \ --id <DB_ID> \ --role <role> \ --service-account-id <service_account_ID> -
To a user group:
yc ydb database add-access-binding \ --id <DB_ID> \ --role <role> \ --subject group:<group_ID>
-
Use the DatabaseService/UpdateAccessBindings gRPC API call and provide the following in the request:
ADDvalue in theaccess_binding_deltas[].actionparameter to add a role.- Role in the
access_binding_deltas[].access_binding.role_idparameter. - ID of the subject you are assigning the role to in the
access_binding_deltas[].access_binding.subject.idparameter. - Type of the subject you are assigning the role to in the
access_binding_deltas[].access_binding.subject.typeparameter.
Assigning multiple roles for a database
- In the management console
, select the folder the database resides in. - Go to Managed Service for YDB.
- Click the name of the database.
- Navigate to
Access bindings and click Assign roles. - Select the group, user, or service account you want to grant access to the database to.
- Click
Add role and select the required roles. - Click Save.
Alert
The set-access-bindings command for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
If 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.
To assign multiple roles for a database:
-
Make sure the database has no roles assigned that you would not want to lose:
yc ydb database list-access-bindings \ --id <DB_ID> -
View the description of the CLI command for assigning roles:
yc ydb database set-access-bindings --help -
Get a list of databases with their IDs:
yc ydb database list -
Get the ID of the user, service account, or user group you are assigning roles to.
-
Use one of the commands below to assign roles:
-
To a Yandex account user or local user:
yc ydb database set-access-bindings \ --id <DB_ID> \ --access-binding role=<role>,user-account-id=<user_ID> -
To a federated user:
yc ydb database set-access-bindings \ --id <DB_ID> \ --access-binding role=<role>,subject=federatedUser:<user_ID> -
To a service account:
yc ydb database set-access-bindings \ --id <DB_ID> \ --access-binding role=<role>,service-account-id=<service_account_ID> -
To a user group:
yc ydb database set-access-bindings \ --id <DB_ID> \ --access-binding role=<role>,subject=group:<group_ID>
Provide a separate
--access-bindingparameter for each role. Here is an example:yc ydb database set-access-bindings \ --id <DB_ID> \ --access-binding role=<role1>,service-account-id=<service_account_ID> \ --access-binding role=<role2>,service-account-id=<service_account_ID> \ --access-binding role=<role3>,service-account-id=<service_account_ID> -
Alert
The setAccessBindings method for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
Use the DatabaseService/SetAccessBindings gRPC API call. In your request, provide an array of objects, each one matching a particular role and containing the following data:
- Role in the
access_bindings[].role_idparameter. - ID of the subject getting the roles in the
access_bindings[].subject.idparameter. - Type of the subject getting the roles in the
access_bindings[].subject.typeparameter.
Deleting a database
- In the management console
, select the folder to delete the database from. - Go to Managed Service for YDB.
- Click
in the row with the database in question and select Delete. - Confirm the deletion.
If 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 delete <DB_name>
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and delete the fragment describing the database.
Example of a database description in the Terraform configuration:
resource "yandex_ydb_database_dedicated" "database2" { name = "test-ydb-dedicated" network_id = yandex_vpc_network.my-net.id subnet_ids = [yandex_vpc_subnet.my-subnet-a.id, yandex_vpc_subnet.my-subnet-b.id, yandex_vpc_subnet.my-subnet-d.id] resource_preset_id = "medium" scale_policy { fixed_scale { size = 1 } } storage_config { group_count = 1 storage_type_id = "ssd" } } -
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.
-
Terraform will delete all the resources as appropriate. You can check the update using the management console
yc ydb database list
To delete the database, use the delete REST API method for the Database resource or the DatabaseService/Delete gRPC API call and specify the ID of the database to delete in the databaseId request parameter.
You can get the database ID with the list of databases.