PostgreSQL version upgrade
You can upgrade a Managed Service for PostgreSQL cluster to version 18 or lower.
Note
Upgrade from a standard cluster version to an 1C:Enterprise version (e.g., 14 to 14-1c) is not supported.
Warning
To upgrade the version, the cluster storage must have at least 10% free space, with a minimum of 10 GB.
You can only upgrade to the next sequential version, e.g., from 14 to 15. Upgrading to subsequent versions must be done incrementally. For example, to upgrade PostgreSQL from version 14 to 16, follow this sequence: 14 → 15 → 16.
In single-host clusters, only the master host is taken offline for upgrades. Such clusters are unavailable for reading and writing during upgrades.
In multi-host clusters, upgrades follow the procedure below:
-
The master host is taken offline for an upgrade. During this time, replicas operate in read-only mode. No failover occurs. After the upgrade, the master host stays offline, even for reads, until all replicas are upgraded.
-
Replicas are taken offline for an upgrade, one by one. The replicas are queued randomly. Once upgraded, replicas resume operation in read-only mode.
A two-host cluster will be unavailable during the upgrade of its replica. In a cluster of three or more hosts, at least one replica will be always available for reading.
-
The master host resumes its operation.
To learn about upgrades within the same version and host maintenance, see Maintenance.
Before a version upgrade
Make sure the upgrade will not disrupt your applications:
- Check the PostgreSQL release notes
to learn how upgrades may affect your applications or installed extensions. - Try upgrading a test cluster. You can deploy it from a backup of the main cluster.
- Create a backup of the main cluster immediately before upgrading.
Upgrading a cluster
Alert
- After the DBMS upgrade, you cannot revert a cluster to the previous version.
- Whether a PostgreSQL version upgrade succeeds depends on multiple factors, including your cluster’s configuration and the nature of the stored data. We recommend you first upgrade a test cluster with the same data and configuration.
- Go to Managed Service for PostgreSQL.
- Select your cluster from the list and click
Edit. - In the Version field, select the new version number.
- Click Save changes.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id options.
To upgrade a cluster to PostgreSQL version 15 or lower:
-
Get a list of your PostgreSQL clusters using this command:
yc managed-postgresql cluster list -
Get the target cluster details and check its PostgreSQL version in the
config.versionsetting:yc managed-postgresql cluster get <cluster_name_or_ID> -
Start the PostgreSQL upgrade:
yc managed-postgresql cluster update <cluster_name_or_ID> \ --postgresql-version <new_version_number>
-
Open the current Terraform configuration file describing your infrastructure.
For more on how to create this file, see Creating a cluster.
For a complete list of configurable Managed Service for PostgreSQL cluster fields, see this Terraform provider guide.
-
Add the
versionfield to thecluster_configsection of the target Managed Service for PostgreSQL cluster, or update its value if it already exists:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... cluster_config { version = "<PostgreSQL_version>" } } -
Validate your configuration.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
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.
How can I change these timeouts?
Add a
timeoutssection to the cluster description, e.g.:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # 1 hour 30 minutes update = "2h" # 2 hours delete = "30m" # 30 minutes } } -
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.Update method, e.g., via the following cURL
request: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
updateMaskparameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.version", "configSpec": { "version": "<PostgreSQL_version>" } }'Where:
-
updateMask: Comma-separated list of settings you want to update.Here, we provide only one setting.
-
configSpec.version: New PostgreSQL version.
You can get the cluster ID with the list of clusters in the folder.
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.Update method, e.g., via the following gRPCurl
request: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_maskparameter as an array ofpaths[]strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }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_mask": { "paths": [ "config_spec.version" ] }, "config_spec": { "version": "<PostgreSQL_version>" } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateWhere:
-
update_mask: List of settings to update as an array of strings (paths[]).Here, we provide only one setting.
-
config_spec.version: New PostgreSQL version.
You can get the cluster ID with the list of clusters in the folder.
-
-
Check the server response to make sure your request was successful.
Once you launch the upgrade, the cluster status changes to UPDATING. Wait for the operation to complete and then check the cluster version.
Cluster upgrade time depends on the database size.
Tip
Contact support
Examples
Suppose you need to upgrade a cluster from version 14 to 15.
-
To get a list of clusters with their IDs and names, run this command:
yc managed-postgresql cluster list+----------------------+---------------+---------------------+--------+---------+ | ID | NAME | CREATED AT | HEALTH | STATUS | +----------------------+---------------+---------------------+--------+---------+ | c9q8p8j2gaih******** | postgre406 | 2021-10-23 12:44:17 | ALIVE | RUNNING | +----------------------+---------------+---------------------+--------+---------+ -
To get information about a cluster named
postgre406, run the following command:yc managed-postgresql cluster get postgre406id: c9q8p8j2gaih******** ... config: version: "14" ... -
To upgrade the
postgre406cluster to version 15, run this command:yc managed-postgresql cluster update postgre406 --postgresql-version 15