[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for YDB](../index.md) > [Step-by-step guides](index.md) > Managing databases

# Managing YDB databases

In Managed Service for YDB, you can create a database in two modes: [serverless](../concepts/serverless-and-dedicated.md#serverless) and [dedicated](../concepts/serverless-and-dedicated.md#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](#serverless).
* [Create and update the parameters of a dedicated database](#dedicated).
* [View a list of databases](#list-db).
* [Delete a database](#delete-db).

## Creating and updating the parameters of a serverless database {#serverless}

### Creating a serverless database {#create-db-serverless}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder for your database.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Click **Create a database**.
  1. 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.

  1. Under **Database type**, select `Serverless`.
  1. Under **Load type**, select one of these options:

      - `OLTP`
      - `OLAP (Analytics β)`

  1. 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](../concepts/serverless-and-dedicated.md).
  1. Click **Create a database**.

   Wait for the database status to change to `Running`.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the Yandex Cloud CLI command for creating a database:

      ```bash
      yc ydb database create --help
      ```

  1. Run this command:

      ```bash
      yc ydb database create <DB_name> --serverless
      ```

      Result:

      ```text
      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](#update-db-serverles) any parameter later by running the `update` Yandex Cloud CLI command or using the management console. For more information, see [Serverless database parameters](../concepts/serverless-and-dedicated.md#serverless-options).

  Every serverless database is created with geographic redundancy across three [availability zones](../../overview/concepts/geo-scope.md).

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the relevant documentation on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. In the Terraform configuration file, define the properties of the serverless database you want to create:

      ```hcl
      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, `true` or `false`. You cannot delete a database with this option enabled. Enabled deletion protection does not protect the database contents. The default value is `false`.
     * `enable_throttling_rcu_limit`: Enable throughput capacity limit, `true` or `false`. This is an optional setting. The default value is `false`.
     * `provisioned_rcu_limit`: Limit on request units consumed per second. This is an optional setting. The default value is `0`.
     * `storage_size_limit`: Data size limit in bytes. This is an optional setting. The default value is `50` GB.
     * `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 is `0`.

  1. Apply the changes:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

    Terraform will create all the required resources. You can check the update using the [management console](https://console.yandex.cloud) or this [Yandex CloudCLI](../../cli/quickstart.md) command:

    ```bash
    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:

    > ```hcl
    > 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
    >   }
    > }
    > ```

- API {#api}

  To create a serverless database, use the [create](../api-ref/Database/create.md) REST API method for the [Database](../api-ref/Database/index.md) resource or the [DatabaseService/Create](../api-ref/grpc/Database/create.md) gRPC API call and provide the following in the request:

  * ID of the folder to host the database in the `folderId` parameter.
  * Database name in the `name` parameter.
  * Database throughput capacity in the `serverlessDatabase.throttlingRcuLimit` parameter.
  * Database size, in bytes, in the `serverlessDatabase.storageSizeLimit` parameter.

{% endlist %}

### Updating serverless database parameters {#update-db-serverless}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you want to update the database settings.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Find the database you need in the list, click ![horizontal-ellipsis](../../_assets/horizontal-ellipsis.svg) in its row, and select **Edit**.
  1. Configure the database:
      1. Change the database name, if required.
      1. Under **Limits**, specify the [throughput capacity](../pricing/serverless.md#prices-ru) and [data size](../pricing/serverless.md#rules-storage).
      1. Under **Pricing**, set the [provisioned throughput capacity](../pricing/serverless.md#prices-ru).
  1. Click **Update database**.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  View the description of the Yandex Cloud CLI command for updating a database:

  ```bash
  yc ydb database update --help
  ```

  Serverless database parameter names start with `sls-`. Other parameters only apply to dedicated databases.

  **Examples**

  1. Renaming the `dbtest` database to `mydb`:

      > ```bash
      > yc ydb database update dbtest \
      >   --new-name mydb
      > ```

  1. Setting a usage limit of 100 request units per second for a serverless database named `db5`:

      > ```bash
      > yc ydb database update db5 \
      >   --sls-throttling-rcu 100
      > ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. Open the Terraform configuration file and edit the fragment describing the serverless database:

      ```hcl
      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, `true` or `false`. You cannot delete a database with this option enabled. Enabled deletion protection does not protect the database contents. The default value is `false`.
     * `enable_throttling_rcu_limit`: Enable throughput capacity limit, `true` or `false`. This is an optional setting. The default value is `false`.
     * `provisioned_rcu_limit`: Limit on request units consumed per second. This is an optional setting. The default value is `0`.
     * `storage_size_limit`: Amount of data, in GB. This is an optional setting. The default value is `50`.
     * `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 is `0`.

  1. Apply the changes:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

    Terraform will apply the required changes to the resources. You can check the update using the [management console](https://console.yandex.cloud) or this [Yandex Cloud CLI](../../cli/quickstart.md) command:

    ```bash
    yc ydb database get <DB_name>
    ```

  **Example**

  Changing the provisioned throughput capacity and amount of data for the `test-ydb-serverless` database:

    > ```hcl
    > 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
    >   }
    > }
    > ```

- API {#api}

  To change the serverless database parameters, use the [update](../api-ref/Database/update.md) REST API method for the [Database](../api-ref/Database/index.md) resource or the [DatabaseService/Update](../api-ref/grpc/Database/update.md) gRPC API call and specify the database ID in the `databaseId` request parameter.

  You can get the database ID with the [list of databases](manage-databases.md#list-db).

   Provide the following in the request:

  * ID of the folder to host the database in the `folderId` parameter.
  * Database name in the `name` parameter.
  * Database throughput capacity in the `serverlessDatabase.throttlingRcuLimit` parameter.
  * Database size, in bytes, in the `serverlessDatabase.storageSizeLimit` parameter.
  * Computing resource ID in the `resourcePresetId` parameter.
  * Network ID in the `networkId` parameter.
  * Storage type in the `storageConfig.storageOptions.storageTypeId` parameter.
  * Number of storage groups in the `storageConfig.storageOptions.groupCount` parameter.
  * Number of database instances in the `scalePolicy.fixedScale.size` parameter.

{% endlist %}

## Creating and updating dedicated database parameters {#dedicated}

### Creating a dedicated database {#create-db-dedicated}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder for your database.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Click **Create a database**.
  1. 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.

  1. Under **Database type**, select `Dedicated`.
  1. Under **Load type**, select one of these options:

      - `OLTP`
      - `OLAP`

  1. Under **Computing resources**, select the type and amount of [computing resources](../concepts/resources.md#resource-presets).

      {% note warning %}

      For reliable and stable performance, a database needs multiple slots. A database run in the production environment must have at least three slots.

      {% endnote %}

  1. Under **Storage groups**, select the disk type and number of [storage groups](../concepts/resources.md#storage-groups) that determines the total amount of storage.
  1. Under **Network**, configure the network:
      1. 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.

          {% note warning %}
          
          For Managed Service for YDB databases with external IP addresses, the outgoing internet traffic consumption is calculated based on the [current pricing policy](../../vpc/pricing.md).
          
          Use grants to offset the charges for outgoing internet traffic generated by Managed Service for YDB usage.
          
          {% endnote %}

      1. 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**.
      1. 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**](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) format.
          * Click **Create subnet**.
  1. Click **Create a database**.

    Wait for the database status to change to `Running`.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the Yandex Cloud CLI command for creating a database:

      ```bash
      yc ydb database create --help
      ```

  1. Run this command:

      ```bash
      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 the `default` network.
        * `--storage`: Storage type and number of [storage groups](../concepts/resources.md#storage-groups) in `type=<storage_type>,groups=<number_of_storage_groups>` format. For the `ssd` type, 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](../concepts/resources.md#resource-presets).

  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, `1` by 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**

  1. Creating a single-node dedicated YDB database with the minimum configuration, named `dedb` and accessible from the internet:

      > ```bash
      > yc ydb database create dedb \
      >   --dedicated \
      >   --network-name default \
      >   --storage type=ssd,groups=1 \
      >   --resource-preset medium \
      >   --public-ip
      > ```

  1. Asynchronously creating a three-node dedicated YDB database with geographic redundancy, 300 GB of storage, and computing nodes with 64 GB RAM each, named `dedb3` and accessible from the internet:

      > ```bash
      > yc ydb database create dedb3 \
      >   --dedicated
      >   --network-name default \
      >   --storage type=ssd,groups=3 \
      >   --resource-preset medium-m64 \
      >   --public-ip \
      >   --fixed-size 3 \
      >   --async
      > ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. In the Terraform configuration file, define the properties of the dedicated database to create:

     ```hcl
      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](../concepts/resources.md#resource-presets).
     * `deletion_protection`: Database deletion protection, `true` or `false`. You cannot delete a database with this option enabled. Enabled deletion protection does not protect the database contents. The default value is `false`.
     * `scale_policy`: Scaling policy, where `size` indicates the number of database instances.
     * `storage_config`: Storage configuration, where:
        * `group_count`: Number of [storage groups](../concepts/resources.md#storage-groups).
        * `storage_type_id`: Storage type. For the `ssd` type, a single storage group can store up to 100 GB of data.

  1. Create a database:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

    Terraform will create all the required resources. You can check the update using the [management console](https://console.yandex.cloud) or this [Yandex Cloud CLI](../../cli/quickstart.md) command:

    ```bash
    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:

    > ```hcl
    > 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"
    >   }
    > }
    > ```

- API {#api}

  To create a dedicated database, use the [create](../api-ref/Database/create.md) REST API method for the [Database](../api-ref/Database/index.md) resource or the [DatabaseService/Create](../api-ref/grpc/Database/create.md) gRPC API call and provide the following in the request:

  * ID of the folder to host the database in the `folderId` parameter.
  * Database name in the `name` parameter.
  * Permission to assign public IP addresses to database nodes in the `dedicatedDatabase.assignPublicIps` parameter.
  * Computing resource ID in the `resourcePresetId` parameter.
  * Network ID in the `networkId` parameter.
  * Storage type in the `storageConfig.storageOptions.storageTypeId` parameter.
  * Number of storage groups in the `storageConfig.storageOptions.groupCount` parameter.
  * Number of database instances in the `scalePolicy.fixedScale.size` parameter.

{% endlist %}

### Updating dedicated database parameters {#update-db-dedicated}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you want to update the database settings.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Find the database you need in the list, click ![horizontal-ellipsis](../../_assets/horizontal-ellipsis.svg) in its row, and select **Edit**.
  1. Configure the database:
      1. Change the database name, if required.
      1. Under **Computing resources**, select the type and amount of [computing resources](../concepts/resources.md#resource-presets).
      1. Under **Storage groups**, select the disk type and number of [storage groups](../concepts/resources.md#storage-groups) that determines the total amount of storage.
  1. Click **Update database**.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  View the description of the Yandex Cloud CLI command for updating a database:

  ```bash
  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:

  > ```bash
  > yc ydb database update test-db \
  >   --storage type=ssd,group=2
  > ```

  You cannot decrease the number of storage groups.

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. Open the Terraform configuration file and edit the fragment describing your database:

      > ```hcl
      > 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"
      >   }
      > }
      > ```

  1. Apply the changes:

     1. In the terminal, navigate to the configuration file directory.
     1. Make sure the configuration is correct using this command:
     
        ```bash
        terraform validate
        ```
     
        If the configuration is valid, you will get this message:
     
        ```bash
        Success! The configuration is valid.
        ```
     
     1. Run this command:
     
        ```bash
        terraform plan
        ```
     
        You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
     1. Apply the configuration changes:
     
        ```bash
        terraform apply
        ```
     
     1. Type `yes` and press **Enter** to confirm the changes.

  You can check the update using the [management console](https://console.yandex.cloud) or this [Yandex CloudCLI](../../cli/quickstart.md) command:

  ```bash
  yc ydb database get <DB_name>
  ```

- API {#api}

  To change the dedicated database parameters, use the [update](../api-ref/Database/update.md) REST API method for the [Database](../api-ref/Database/index.md) resource or the [DatabaseService/Update](../api-ref/grpc/Database/update.md) gRPC API call and specify the database ID in the `databaseId` request parameter.

  You can get the database ID with the [list of databases](manage-databases.md#list-db).

  In the request, provide a set of parameters used when [creating the dedicated database](#create-db-dedicated) with your updated values.

{% endlist %}

To move a database to a different availability zone, follow [this guide](migration-to-an-availability-zone.md).

## Viewing the list of databases {#list-db}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder to get a list of databases for.
  1. Navigate to **Managed Service for&nbsp;YDB**.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  Run this command:

  ```bash
  yc ydb database list
  ```

- API {#api}

  To get a list of databases in the folder, use the [list](../api-ref/Database/list.md) REST API method for the [Database](../api-ref/Database/index.md) resource or the [DatabaseService/List](../api-ref/grpc/Database/list.md) gRPC API call and provide the folder ID in the `folderId` request parameter.

{% endlist %}

## Assigning a role for a database {#add-access-binding}

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](../../iam/concepts/access-control/roles.md) for the database. To choose the one you need, [learn](../security/index.md#roles-list) about the existing roles.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder the database resides in.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Click the name of the database.
  1. Navigate to ![image](../../_assets/console-icons/persons.svg) **Access bindings** and click **Assign roles**.
  1. Select the group, user, or service account you want to grant access to the database to.
  1. Click ![image](../../_assets/console-icons/plus.svg) **Add role** and select the required roles.
  1. Click **Save**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To assign a role for a database:

  1. View the description of the CLI command for assigning roles:

     ```bash
     yc ydb database add-access-binding --help
     ```

  1. Get a list of databases with their IDs:

     ```bash
     yc ydb database list
     ```

  1. Get the [ID of the user](../../organization/operations/users-get.md), [service account](../../iam/operations/sa/get-id.md), or user group you are assigning a role to.
  1. Use one of these commands to assign a role:

     * To a user:

        ```bash
        yc ydb database add-access-binding \
           --id <DB_ID> \
           --role <role> \
           --user-account-id <user_ID>
        ```

     * To a federated user:

        ```bash
        yc ydb database add-access-binding \
           --id <DB_ID> \
           --role <role> \
           --user-account-id <user_ID>
        ```

     * To a service account:

        ```bash
        yc ydb database add-access-binding \
           --id <DB_ID> \
           --role <role> \
           --service-account-id <service_account_ID>
        ```

     * To a user group:

        ```bash
        yc ydb database add-access-binding \
           --id <DB_ID> \
           --role <role> \
           --subject group:<group_ID>
        ```

- API {#api}

  Use the [DatabaseService/UpdateAccessBindings](../api-ref/grpc/Database/updateAccessBindings.md) gRPC API call and provide the following in the request:

  * `ADD` value in the `access_binding_deltas[].action` parameter to add a role.
  * Role in the `access_binding_deltas[].access_binding.role_id` parameter.
  * ID of the subject you are assigning the role to in the `access_binding_deltas[].access_binding.subject.id` parameter.
  * Type of the subject you are assigning the role to in the `access_binding_deltas[].access_binding.subject.type` parameter.

{% endlist %}

## Assigning multiple roles for a database {#set-access-bindings}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder the database resides in.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Click the name of the database.
  1. Navigate to ![image](../../_assets/console-icons/persons.svg) **Access bindings** and click **Assign roles**.
  1. Select the group, user, or service account you want to grant access to the database to.
  1. Click ![image](../../_assets/console-icons/plus.svg) **Add role** and select the required roles.
  1. Click **Save**.

- CLI {#cli}

  {% note alert %}
  
  The `set-access-bindings` command for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
  
  {% endnote %}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To assign multiple roles for a database:

  1. Make sure the database has no roles assigned that you would not want to lose:

     ```bash
     yc ydb database list-access-bindings \
        --id <DB_ID>
     ```

  1. View the description of the CLI command for assigning roles:

     ```bash
     yc ydb database set-access-bindings --help
     ```

  1. Get a list of databases with their IDs:

     ```bash
     yc ydb database list
     ```

  1. Get the [ID of the user](../../organization/operations/users-get.md), [service account](../../iam/operations/sa/get-id.md), or user group you are assigning roles to.
  1. Use one of the commands below to assign roles:

     * To a Yandex account user or local user:

        ```bash
        yc ydb database set-access-bindings \
           --id <DB_ID> \
           --access-binding role=<role>,user-account-id=<user_ID>
        ```

     * To a federated user:

        ```bash
        yc ydb database set-access-bindings \
           --id <DB_ID> \
           --access-binding role=<role>,subject=federatedUser:<user_ID>
        ```

     * To a service account:

        ```bash
        yc ydb database set-access-bindings \
           --id <DB_ID> \
           --access-binding role=<role>,service-account-id=<service_account_ID>
        ```

     * To a user group:

        ```bash
        yc ydb database set-access-bindings \
           --id <DB_ID> \
           --access-binding role=<role>,subject=group:<group_ID>
        ```

     Provide a separate `--access-binding` parameter for each role. Here is an example:

     ```bash
     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>
     ```

- API {#api}

  {% note alert %}
  
  The `setAccessBindings` method for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
  
  {% endnote %}

  Use the [DatabaseService/SetAccessBindings](../api-ref/grpc/Database/setAccessBindings.md) 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_id` parameter.
  * ID of the subject getting the roles in the `access_bindings[].subject.id` parameter.
  * Type of the subject getting the roles in the `access_bindings[].subject.type` parameter.

{% endlist %}

## Deleting a database {#delete-db}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder to delete the database from.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Find the database you need in the list, click ![horizontal-ellipsis](../../_assets/horizontal-ellipsis.svg) in its row, and select **Delete**.
  1. Confirm the deletion.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  Run this command:

    ```bash
    yc ydb database delete <DB_name>
    ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. Open the Terraform configuration file and delete the fragment describing the database.

     Example of a database description in the Terraform configuration:

     ```hcl
     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"
       }
     }
     ```

  1. Apply the changes:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

    Terraform will delete all the resources as appropriate. You can check the update using the [management console](https://console.yandex.cloud) or this [Yandex Cloud CLI](../../cli/quickstart.md) command:

    ```bash
    yc ydb database list
    ```

- API {#api}

  To delete the database, use the [delete](../api-ref/Database/delete.md) REST API method for the [Database](../api-ref/Database/index.md) resource or the [DatabaseService/Delete](../api-ref/grpc/Database/delete.md) 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](manage-databases.md#list-db).

{% endlist %}