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

# Managing PostgreSQL cluster hosts

You can add and remove cluster hosts, as well as manage their settings. To learn how to move cluster hosts to a different [availability zone](../../overview/concepts/geo-scope.md), see [this guide](host-migration.md).

## Getting a list of cluster hosts {#list}

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;PostgreSQL**.
  1. Click the name of your cluster and select the **Hosts** tab.

- 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 get a list of cluster hosts, run this command:

  ```bash
  yc managed-postgresql host list \
    --cluster-name <cluster_name>
  ```

  Result:

  
  ```text
  +----------------------------+----------------------+---------+--------+--------------------+
  |            NAME            |      CLUSTER ID      |  ROLE   | HEALTH |      ZONE ID       |
  +----------------------------+----------------------+---------+--------+--------------------+
  | rc1b***mdb.yandexcloud.net | c9qp71dk1dfg******** | MASTER  | ALIVE  | ru-central1-b      |
  | rc1a***mdb.yandexcloud.net | c9qp71dk1dfg******** | REPLICA | ALIVE  | ru-central1-a      |
  +----------------------------+----------------------+---------+--------+--------------------+
  ```


  You can get the cluster name from the [list of clusters in the folder](cluster-list.md#list-clusters).

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Call the [Cluster.ListHosts](../api-ref/Cluster/listHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

     ```bash
     curl \
       --request GET \
       --header "Authorization: Bearer $IAM_TOKEN" \
       --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/hosts'
     ```

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/listHosts.md#yandex.cloud.mdb.postgresql.v1.ListClusterHostsResponse) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.ListHosts](../api-ref/grpc/Cluster/listHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

     ```bash
     grpcurl \
       -format json \
       -import-path ~/cloudapi/ \
       -import-path ~/cloudapi/third_party/googleapis/ \
       -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \
       -rpc-header "Authorization: Bearer $IAM_TOKEN" \
       -d '{
             "cluster_id": "<cluster_ID>"
           }' \
       mdb.api.cloud.yandex.net:443 \
       yandex.cloud.mdb.postgresql.v1.ClusterService.ListHosts
     ```

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/listHosts.md#yandex.cloud.mdb.postgresql.v1.ListClusterHostsResponse) to make sure your request was successful.

{% endlist %}

## Creating a host {#add}

The number of hosts in Managed Service for PostgreSQL clusters is limited by the CPU and RAM quotas allocated to database clusters in your cloud. To review your resource usage, open the [Quotas](https://console.yandex.cloud/cloud?section=quotas) page and find the **Managed Databases** section.

{% list tabs group=instructions %}

- Management console {#console}

  To create a host:
  1. Navigate to **Managed Service for&nbsp;PostgreSQL**.
  1. Click the cluster name and navigate to the **Hosts** tab.
  1. Click **Create host**.

  
  1. Specify the following host settings:
     * Availability zone.
     * Subnet (if the required subnet is not on the list, [create it](../../vpc/operations/subnet-create.md)).
     * Replication source (if you use [cascading replication](../concepts/replication.md#replication-manual)).
     * To make the host accessible from outside Yandex Cloud, select **Public access**.


- 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 create a host:

  
  1. To choose a subnet for your new host, get the list of all cluster subnets:

     ```bash
     yc vpc subnet list
     ```

     Result:

     ```text
     +----------------------+-----------+----------------------+---------------+-------------------+
     |          ID          |   NAME    |      NETWORK ID      |      ZONE     |      RANGE        |
     +----------------------+-----------+----------------------+---------------+-------------------+
     | b0cl69q1w2e3******** | default-d | enp6rq71w2e3******** | ru-central1-d | [172.16.**.**/20] |
     | e2lkj9q1w2e3******** | default-b | enp6rq71w2e3******** | ru-central1-b | [10.10.**.**/16]  |
     | e9b0phq1w2e3******** | a-2       | enp6rq71w2e3******** | ru-central1-a | [172.16.**.**/20] |
     | e9b9v2q1w2e3******** | default-a | enp6rq71w2e3******** | ru-central1-a | [172.16.**.**/20] |
     +----------------------+-----------+----------------------+---------------+-------------------+
     ```

     If the required subnet is not on the list, [create it](../../vpc/operations/subnet-create.md).


  1. See the description of the CLI command for adding a host:

     ```bash
     yc managed-postgresql host add --help
     ```

  1. Run the command for adding a host:

     
     ```bash
     yc managed-postgresql host add \
       --cluster-name <cluster_name> \
       --host zone-id=<availability_zone>,subnet-id=<subnet_ID>
     ```


     
     You should specify the subnet ID if the availability zone contains more than one subnet; otherwise, Managed Service for PostgreSQL will automatically select the only subnet. You can get the cluster name from the [list of clusters in your folder](cluster-list.md#list-clusters).

     You can specify extra options in the `--host` argument to manage public access to the host and cluster replication:
     * Use the host’s `replication-source` option for [manual replication stream management](../concepts/replication.md#replication-manual).
     * Use the `assign-public-ip` option to make the host accessible from outside Yandex Cloud:
       * `true`: Public access enabled.
       * `false`: Public access disabled.


  Managed Service for PostgreSQL will start the host addition process.


- Terraform {#tf}

  To create a host:
  1. Open the current Terraform configuration file describing your infrastructure.

     For more on how to create this file, see [Creating a cluster](cluster-create.md).

     For a complete list of configurable Managed Service for PostgreSQL cluster fields, see [this Terraform provider guide](../../terraform/resources/mdb_postgresql_cluster.md).
  1. Add a `host` section to the Managed Service for PostgreSQL cluster description:

     ```hcl
     resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
       ...
       host {
         name                    = "<host_name>"
         zone                    = "<availability_zone>"
         subnet_id               = "<subnet_ID>"
         replication_source_name = "<replication_source>"
         assign_public_ip        = <public_access_to_host>
       }
     }
     ```

     Where:

     * `name`: Host name.
     * `zone`: Availability zone.
     * `subnet_id`: Subnet ID.
     * `replication_source_name`: Replication source, i.e., the `name` attribute of the corresponding `host` section.
     * `assign_public_ip`: [Public access to the host](../concepts/network.md#public-access-to-a-host), `true` or `false`.

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm updating the resources.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

     {% note warning "Timeouts" %}
     
     The Terraform provider sets the following timeouts for Managed Service for PostgreSQL cluster operations:
     
     * Creating a cluster, including restoration from a backup: 30 minutes.
     * Updating a cluster: 60 minutes.
     * Deleting a cluster: 15 minutes.
     
     Operations exceeding the timeout are aborted.
     
     {% cut "How can I change these timeouts?" %}
     
     Add a `timeouts` section to the cluster description, e.g.:
     
     ```hcl
     resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
       ...
       timeouts {
         create = "1h30m" # 1 hour 30 minutes
         update = "2h"    # 2 hours
         delete = "30m"   # 30 minutes
       }
     }
     ```
     
     {% endcut %}
     
     {% endnote %}


- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Call the [Cluster.AddHosts](../api-ref/Cluster/addHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

     
     ```bash
     curl \
       --request POST \
       --header "Authorization: Bearer $IAM_TOKEN" \
       --header "Content-Type: application/json" \
       --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/hosts:batchCreate' \
       --data '{
                 "hostSpecs": [
                   {
                     "zoneId": "<availability_zone>",
                     "subnetId": "<subnet_ID>",
                     "assignPublicIp": <allow_public_access_to_host>,
                     "replicationSource": "<host_FQDN>",
                     "priority": "<host_priority>",
                     "configSpec": {
                       "postgresqlConfig_<PostgreSQL_version>": {
                         <PostgreSQL_settings>
                       }
                     }
                   },
                   { <similar_settings_for_new_host_2> },
                   { ... },
                   { <similar_settings_for_new_host_N> }
                 ]
               }'
     ```


     Where `hostSpecs` is the array of new hosts. Each array element contains the configuration for a single host and has the following structure:

     * `zoneId`: Availability zone.

     
     * `subnetId`: Subnet ID.
     * `assignPublicIp`: Internet access to the host via a public IP address, `true` or `false`.


     * `replicationSource`: Host’s replication source for [manual replication stream management](../concepts/replication.md#replication-manual). Specify the [FQDN of the host](connect/fqdn.md#special-fqdns) that will be used as the replication source.
     * `priority`: Host priority relative to all other hosts.
     * `configSpec.postgresqlConfig_<PostgreSQL_version>`: PostgreSQL settings. Specify each setting on a separate line, separated by commas.

       See the [method description](../api-ref/Cluster/addHosts.md#yandex.cloud.mdb.postgresql.v1.AddClusterHostsRequest) for the list of PostgreSQL versions available for the parameter. See [PostgreSQL settings](../concepts/settings-list.md) for descriptions and possible values of the settings.

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.AddHosts](../api-ref/grpc/Cluster/addHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

     
     ```bash
     grpcurl \
       -format json \
       -import-path ~/cloudapi/ \
       -import-path ~/cloudapi/third_party/googleapis/ \
       -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \
       -rpc-header "Authorization: Bearer $IAM_TOKEN" \
       -d '{
             "cluster_id": "<cluster_ID>",
             "host_specs": [
               {
                 "zone_id": "<availability_zone>",
                 "subnet_id": "<subnet_ID>",
                 "assign_public_ip": <allow_public_access_to_host>,
                 "replication_source": "<host_FQDN>",
                 "priority": "<host_priority>",
                 "config_spec": {
                   "postgresql_config_<PostgreSQL_version>": {
                     <PostgreSQL_settings>
                   }
                 }
               },
               { <similar_settings_for_new_host_2> },
               { ... },
               { <similar_settings_for_new_host_N> }
             ]
           }' \
       mdb.api.cloud.yandex.net:443 \
       yandex.cloud.mdb.postgresql.v1.ClusterService.AddHosts
     ```


     Where `host_specs` is an array of new hosts. Each array element contains the configuration for a single host and has the following structure:

     * `zone_id`: Availability zone.

     
     * `subnet_id`: Subnet ID.
     * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`.


     * `replication_source`: Host’s replication source for [manual replication stream management](../concepts/replication.md#replication-manual). Specify the [FQDN of the host](connect/fqdn.md#special-fqdns) that will be used as the replication source.
     * `priority`: Host priority relative to all other hosts.
     * `config_spec.postgresql_config_<PostgreSQL_version>`: PostgreSQL settings. Enter each setting on a new line, separated by commas.

       See the [method description](../api-ref/grpc/Cluster/create.md#yandex.cloud.mdb.postgresql.v1.ConfigHostSpec) for the list of PostgreSQL versions available for the parameter. See [PostgreSQL settings](../concepts/settings-list.md) for a description and possible values for each setting.

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you cannot [connect](connect/index.md) to the host you added, check that the cluster [security group](../concepts/network.md#security-groups) is properly configured for the subnet containing your host.

{% endnote %}


## Updating a host {#update}

In a Managed Service for PostgreSQL cluster, you can configure the [replication](../concepts/replication.md) source and [public access](../concepts/network.md#public-access-to-a-host) for each host.

{% list tabs group=instructions %}

- Management console {#console}

  To change the cluster host settings:
  1. Navigate to **Managed Service for&nbsp;PostgreSQL**.
  1. Click the name of your cluster and select the **Hosts** tab.
  1. Find the host you need in the list, click ![image](../../_assets/console-icons/ellipsis.svg) in its row, then select **Edit**.
  1. Specify new host settings:
     1. Select the host’s replication source for [manual replication stream management](../concepts/replication.md#replication-manual).

     
     1. Enable **Public access** if you want the host to be accessible from outside of Yandex Cloud.


  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 update the cluster host’s settings, run the following command:

  
  ```bash
  yc managed-postgresql host update <host_name> \
    --cluster-name <cluster_name> \
    --replication-source <source_host_name> \
    --assign-public-ip=<public_access_to_host>
  ```


  Where:

  * `cluster-name`: Cluster name.
  * `replication-source`: Source host name.

  
  * `assign-public-ip`: [Public access to the host](../concepts/network.md#public-access-to-a-host), `true` or `false`.


  You can get the host name with the [list of cluster hosts](#list), and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).

  For [manual replication stream management](../concepts/replication.md#replication-manual) within your cluster, change the value of the host's `--replication-source` argument.


- Terraform {#tf}

  To change the cluster host settings:
  1. Open the current Terraform configuration file describing your infrastructure.

     For more on how to create this file, see [Creating a cluster](cluster-create.md).

     For a complete list of configurable Managed Service for PostgreSQL cluster fields, see [this Terraform provider guide](../../terraform/resources/mdb_postgresql_cluster.md).
  1. In the Managed Service for PostgreSQL cluster description, change the attributes of the `host` section referring to the host you want to update.

     ```hcl
     resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
       ...
       host {
         replication_source_name = "<replication_source>"
         assign_public_ip        = <public_access_to_host>
       }
     }
     ```

  Where:

  * `replication_source_name`: Replication source, i.e., the `name` attribute of the corresponding `host` section.
  * `assign_public_ip`: [Public access to the host](../concepts/network.md#public-access-to-a-host), `true` or `false`.

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm updating the resources.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

     {% note warning "Timeouts" %}
     
     The Terraform provider sets the following timeouts for Managed Service for PostgreSQL cluster operations:
     
     * Creating a cluster, including restoration from a backup: 30 minutes.
     * Updating a cluster: 60 minutes.
     * Deleting a cluster: 15 minutes.
     
     Operations exceeding the timeout are aborted.
     
     {% cut "How can I change these timeouts?" %}
     
     Add a `timeouts` section to the cluster description, e.g.:
     
     ```hcl
     resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
       ...
       timeouts {
         create = "1h30m" # 1 hour 30 minutes
         update = "2h"    # 2 hours
         delete = "30m"   # 30 minutes
       }
     }
     ```
     
     {% endcut %}
     
     {% endnote %}


- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Call the [Cluster.UpdateHosts](../api-ref/Cluster/updateHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

     {% note warning %}
     
     The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
     
     {% endnote %}

     
     ```bash
     curl \
       --request POST \
       --header "Authorization: Bearer $IAM_TOKEN" \
       --header "Content-Type: application/json" \
       --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/hosts:batchUpdate' \
       --data '{
                 "updateHostSpecs": [
                   {
                     "updateMask": "assignPublicIp,replicationSource,priority,configSpec.postgresqlConfig_<PostgreSQL_version>",
                     "hostName": "<host_FQDN>",
                     "assignPublicIp": <allow_public_access_to_host>,
                     "replicationSource": "<host_FQDN>",
                     "priority": "<host_priority>",
                     "configSpec": {
                       "postgresqlConfig_<PostgreSQL_version>": {
                         <PostgreSQL_settings>
                       }
                     }
                   },
                   { <similar_settings_for_host_2_being_changed> },
                   { ... },
                   { <similar_settings_for_host_N_being_changed> }
                 ]
               }'
     ```


     Where `updateHostSpecs` is the array of hosts you are updating. Each array element contains the configuration for a single host and has the following structure:

     * `updateMask`: Comma-separated string of settings to update.
     * `hostName`: [FQDN of the host being updated](connect/fqdn.md).

     
     * `assignPublicIp`: Internet access to the host via a public IP address, `true` or `false`.


     * `replicationSource`: Host’s replication source for [manual replication stream management](../concepts/replication.md#replication-manual). Specify the FQDN of the host that will be used as the replication source.
     * `priority`: Host priority relative to all other hosts.
     * `configSpec.postgresqlConfig_<PostgreSQL_version>`: PostgreSQL settings. Enter each setting on a new line, separated by commas.

       See the [method description](../api-ref/Cluster/updateHosts.md#yandex.cloud.mdb.postgresql.v1.UpdateClusterHostsRequest) for the list of PostgreSQL versions available for the parameter. See [PostgreSQL settings](../concepts/settings-list.md) for a description and possible values for each setting.

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.UpdateHosts](../api-ref/grpc/Cluster/updateHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

     {% note warning %}
     
     The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
     
     {% cut "Format for listing settings" %}
     
     ```yaml
     "update_mask": {
         "paths": [
             "<setting_1>",
             "<setting_2>",
             ...
             "<setting_N>"
         ]
     }
     ```
     
     {% endcut %}
     
     {% endnote %}

     
     ```bash
     grpcurl \
       -format json \
       -import-path ~/cloudapi/ \
       -import-path ~/cloudapi/third_party/googleapis/ \
       -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \
       -rpc-header "Authorization: Bearer $IAM_TOKEN" \
       -d '{
             "cluster_id": "<cluster_ID>",
             "update_host_specs": [
               {
                 "update_mask": {
                     "paths": [
                       "assign_public_ip",
                       "replication_source",
                       "priority",
                       "config_spec.postgresql_config_16"
                     ]
                 },
                 "host_name": "<host_FQDN>",
                 "assign_public_ip": <allow_public_access_to_host>,
                 "replication_source": "<host_FQDN>",
                 "priority": "<host_priority>",
                 "config_spec": {
                   "postgresql_config_<PostgreSQL_version>": {
                     <PostgreSQL_settings>
                   }
                 }
               }
             ]
           }' \
       mdb.api.cloud.yandex.net:443 \
       yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateHosts
     ```


     Where `update_host_specs` is an array of hosts you want to update. Each array element contains the configuration for a single host and has the following structure:

     * `update_mask`: List of settings to update as an array of strings (`paths[]`).
     * `host_name`: [FQDN of the host being updated](connect/fqdn.md).

     
     * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`.


     * `replication_source`: Host’s replication source for [manual replication stream management](../concepts/replication.md#replication-manual). Specify the FQDN of the host that will be used as the replication source.
     * `priority`: Host priority relative to all other hosts.
     * `config_spec.postgresql_config_<PostgreSQL_version>`: PostgreSQL settings. Enter each setting on a new line, separated by commas.

       See the [method description](../api-ref/grpc/Cluster/create.md#yandex.cloud.mdb.postgresql.v1.ConfigHostSpec) for the list of PostgreSQL versions available for the parameter. See [PostgreSQL settings](../concepts/settings-list.md) for a description and possible values for each setting.

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you cannot [connect](connect/index.md) to the host after the update, check that the cluster [security group](../concepts/network.md#security-groups) is properly configured for the host's subnet.

{% endnote %}


## Deleting a host {#remove}

You can delete a host from a PostgreSQL cluster as long as it is not the only host in the cluster. To replace the only host, first create a new host and then delete the old one.

If you are deleting the master host, Managed Service for PostgreSQL will automatically promote the highest priority replica to master.

{% list tabs group=instructions %}

- Management console {#console}

  To delete a host from a cluster:
  1. Navigate to **Managed Service for&nbsp;PostgreSQL**.
  1. Click the name of your cluster and select the **Hosts** tab.
  1. Find the host you need in the list, click ![image](../../_assets/console-icons/ellipsis.svg) in its row, select **Delete**, and confirm the deletion.

- 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 delete a host from a cluster, run this command:

  ```bash
  yc managed-postgresql host delete <host_name> \
    --cluster-name <cluster_name>
  ```

  You can get the host name with the [list of cluster hosts](#list), and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).

- Terraform {#tf}

  To delete a host from a cluster:
  1. Open the current Terraform configuration file describing your infrastructure.

     For more on how to create this file, see [Creating a cluster](cluster-create.md).

     For a complete list of configurable Managed Service for PostgreSQL cluster fields, see [this Terraform provider guide](../../terraform/resources/mdb_postgresql_cluster.md).
  1. Delete the `host` section referring to the host you want to delete from the Managed Service for PostgreSQL cluster description.
  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Type `yes` and press **Enter**.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

     {% note warning "Timeouts" %}
     
     The Terraform provider sets the following timeouts for Managed Service for PostgreSQL cluster operations:
     
     * Creating a cluster, including restoration from a backup: 30 minutes.
     * Updating a cluster: 60 minutes.
     * Deleting a cluster: 15 minutes.
     
     Operations exceeding the timeout are aborted.
     
     {% cut "How can I change these timeouts?" %}
     
     Add a `timeouts` section to the cluster description, e.g.:
     
     ```hcl
     resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
       ...
       timeouts {
         create = "1h30m" # 1 hour 30 minutes
         update = "2h"    # 2 hours
         delete = "30m"   # 30 minutes
       }
     }
     ```
     
     {% endcut %}
     
     {% endnote %}

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Call the [Cluster.DeleteHosts](../api-ref/Cluster/deleteHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

     ```bash
     curl \
       --request POST \
       --header "Authorization: Bearer $IAM_TOKEN" \
       --header "Content-Type: application/json" \
       --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/hosts:batchDelete' \
       --data '{
                 "hostNames": [
                   "<host_FQDN>"
                 ]
               }'
     ```

     Where `hostNames` is an array of strings, each containing an [FQDN of the host targeted for deletion](connect/fqdn.md).

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

     ```bash
     export IAM_TOKEN="<IAM_token>"
     ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.DeleteHosts](../api-ref/grpc/Cluster/deleteHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

     ```bash
     grpcurl \
       -format json \
       -import-path ~/cloudapi/ \
       -import-path ~/cloudapi/third_party/googleapis/ \
       -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \
       -rpc-header "Authorization: Bearer $IAM_TOKEN" \
       -d '{
             "cluster_id": "<cluster_ID>",
             "host_names": [
               "<host_FQDN>"
             ]
           }' \
       mdb.api.cloud.yandex.net:443 \
       yandex.cloud.mdb.postgresql.v1.ClusterService.DeleteHosts
     ```

     Where `host_names` is an array of strings, each containing an [FQDN of the host targeted for deletion](connect/fqdn.md).

     You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}