Managing PostgreSQL cluster hosts
You can add and remove cluster hosts and manage their settings. To move cluster hosts to a different availability zone, read this guide.
Getting a list of cluster hosts
- Go to the folder page and select Managed Service for PostgreSQL.
- Click the cluster name and select the Hosts tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of cluster hosts, run the command:
yc managed-postgresql host list \
--cluster-name <cluster_name>
Result:
+----------------------------+----------------------+---------+--------+--------------------+
| 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 request the cluster name with a list of clusters in the folder.
To get a list of cluster hosts, use the listHosts REST API method for the Cluster resource or the ClusterService/ListHosts gRPC API call and provide the cluster ID in the clusterId
request parameter.
You can get the cluster ID with a list of clusters in the folder.
Adding a host
The number of hosts in Managed Service for PostgreSQL clusters is limited by the CPU and RAM quotas available to DB clusters in your cloud. To check the resources in use, open the Quotas
To add a host to the cluster:
-
Go to the folder page and select Managed Service for PostgreSQL.
-
Click the cluster name and go to the Hosts tab.
-
Click
Add host. -
Specify the host parameters:
- Availability zone.
- Subnet (if the required subnet is not on the list, create it).
- Replication source (if you use cascading replication).
- Select Public access if the host must be accessible from outside Yandex Cloud.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To add a host to the cluster:
-
Request a list of cluster subnets to select one for the new host:
yc vpc subnet list
Result:
+----------------------+-----------+----------------------+---------------+-------------------+ | 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 in the list, create it.
-
View a description of the CLI command for adding a host:
yc managed-postgresql host add --help
-
Run the add host command:
yc managed-postgresql host add --cluster-name <cluster_name> --host zone-id=<availability_zone>,subnet-id=<subnet_ID>
The subnet ID should be specified if the availability zone contains multiple subnets; otherwise, Managed Service for PostgreSQL will automatically select a single subnet. You can request the cluster name with a list of clusters in the folder.
You can also specify several additional options in the
--host
parameter to manage public access to a host and replication in a cluster:- Replication source for the host in the
replication-source
option to manually manage replication threads. - External host visibility Yandex Cloud in the
assign-public-ip
option:true
: public access enabled.false
: public access disabled.
- Replication source for the host in the
Managed Service for PostgreSQL will run the add host operation.
To add a host to the cluster:
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about how to create this file, see Creating clusters.
For a complete list of available Managed Service for PostgreSQL cluster configuration fields, see the Terraform provider documentation
. -
Add the
host
block to the Managed Service for PostgreSQL cluster description.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., thename
attribute of the correspondinghost
section.assign_public_ip
: Public access to the host,true
orfalse
.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
Time limits
A Terraform provider sets the timeout for Managed Service for PostgreSQL cluster operations:
- Creating a cluster, including restoring from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?Add the
timeouts
block to the cluster description, for example:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # 1 hour 30 minutes update = "2h" # 2 hours delete = "30m" # 30 minutes } }
-
To add a host to a cluster, use the addHosts REST API method for the Cluster resource or the ClusterService/AddHosts gRPC API call and provide the cluster ID in the clusterId
request parameter.
You can get the cluster ID with a list of clusters in the folder.
Warning
If you cannot connect to the added host, check that the cluster security group is configured correctly for the subnet where you placed the host.
Changing a host
For each host in a Managed Service for PostgreSQL cluster, you can specify the replication source and manage host public access.
To change the parameters of the cluster host:
- Go to the folder page and select Managed Service for PostgreSQL.
- Click the cluster name and open the Hosts tab.
- Click the
icon in the required host row and select Edit. - Set new settings for the host:
- Select the replication source for the host to manually manage replication threads.
- Enable Public access if the host must be accessible from outside Yandex Cloud.
- Click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To change the parameters of a host in a cluster, run the command below:
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,true
orfalse
.
You can request the host name with a list of cluster hosts, and the cluster name, with a list of clusters in the folder.
To manually manage replication threads in the cluster, change the host's replication source in the --replication-source
parameter.
To change the parameters of the cluster host:
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about how to create this file, see Creating clusters.
For a complete list of available Managed Service for PostgreSQL cluster configuration fields, see the Terraform provider documentation
. -
In the Managed Service for PostgreSQL cluster description, change the attributes of the
host
block corresponding to the host you are updating.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., thename
attribute of the correspondinghost
section.assign_public_ip
: Public access to the host,true
orfalse
.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
Time limits
A Terraform provider sets the timeout for Managed Service for PostgreSQL cluster operations:
- Creating a cluster, including restoring from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?Add the
timeouts
block to the cluster description, for example:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # 1 hour 30 minutes update = "2h" # 2 hours delete = "30m" # 30 minutes } }
-
To update host parameters, use the updateHosts REST API method for the Cluster resource or the ClusterService/UpdateHosts gRPC API call and provide the following in the request:
-
Cluster ID in the
clusterId
parameter. To find out the cluster ID, get a list of clusters in the folder. -
One or more objects containing the updated hosts' settings in the
updateHostSpecs
parameter.For each host, specify:
- Name in the
hostName
field. - List of settings to update, in the
updateMask
parameter.
- Name in the
Warning
This API method overrides all parameters of the object being modified that were not explicitly passed in the request to the default values. To avoid this, list the settings you want to change in the updateMask
parameter (one line separated by commas).
Warning
If you cannot connect to the changed host, check that the cluster's security group is configured correctly for the subnet where you placed the host.
Removing a host
You can remove a host from a PostgreSQL cluster if it is not the only host in it. To replace a single host, first create a new host and then remove the old one.
If the host is the master when deleted, Managed Service for PostgreSQL automatically assigns the next highest-priority replica as the master.
To remove a host from a cluster:
- Go to the folder page and select Managed Service for PostgreSQL.
- Click the cluster name and open the Hosts tab.
- Click
in the required host row, select Delete, and confirm the deletion.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To remove a host from the cluster, run:
yc managed-postgresql host delete <host_name>
--cluster-name <cluster_name>
You can request the host name with a list of cluster hosts, and the cluster name, with a list of clusters in the folder.
To remove a host from a cluster:
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about how to create this file, see Creating clusters.
For a complete list of available Managed Service for PostgreSQL cluster configuration fields, see the Terraform provider documentation
. -
Delete the corresponding
host
block from the Managed Service for PostgreSQL cluster description. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Type
yes
and press Enter.-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
Time limits
A Terraform provider sets the timeout for Managed Service for PostgreSQL cluster operations:
- Creating a cluster, including restoring from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?Add the
timeouts
block to the cluster description, for example:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # 1 hour 30 minutes update = "2h" # 2 hours delete = "30m" # 30 minutes } }
-
To delete a host, use the deleteHosts REST API method for the Cluster resource or the ClusterService/DeleteHosts gRPC API call and provide the cluster ID in the clusterId
request parameter.
You can get the cluster ID with a list of clusters in the folder.