Managing backups in Managed Service for PostgreSQL
You can create backups and use existing backups to restore your clusters.
Managed Service for PostgreSQL automatically takes a daily backup as well. You can specify the backup start time and configure its retention period.
Restoring a cluster from a backup
Warning
For clusters running an unsupported DBMS version, restoring from backups is not available.
Point-in-Time Recovery (PITR) technology allows you to restore the cluster’s state to any point in time within the interval from the creation of the oldest full backup to the archiving of the most recent write ahead log (WAL). For more information, see Backups.
When you restore a cluster from a backup, you create a new cluster with the backup data. If your folder lacks resources to create such a cluster, you will not be able to restore from the backup. The average backup recovery speed is 10 MBps per database core.
When restored from a backup, the cluster is recovered as a whole, with all its databases. You cannot select specific databases.
Specify all the required settings for the new cluster.
When restored to the current point in time, the new cluster will reflect the state of:
- Existing cluster at the time of recovery.
- Deleted cluster at the time of archiving its most recent WAL.
Before you begin, assign to your Yandex Cloud account the managed-postgresql.restorer role or higher for the backup folder and the new cluster folder.
Warning
For manually created backups:
- Point-in-time recovery to an arbitrary timestamp is not available.
- You can only restore the cluster to its state right after backup completion.
To restore an existing cluster from a backup:
-
Go to Managed Service for PostgreSQL.
-
Click the name of your cluster and select the Backups tab.
-
Click
for the backup you need, then click Restore cluster. -
Set up the new cluster. You can select a folder for the new cluster from the Folder list.
-
To restore the cluster state to a specific point in time after the backup was created, configure Date and time of recovery (UTC) accordingly. You can either specify the date manually or select it using the date picker.
If you leave this setting as is, the cluster will be restored to the state when the backup was completed.
-
Click Restore cluster.
To restore a previously deleted cluster from a backup:
-
Go to Managed Service for PostgreSQL.
-
Select the Backups tab.
-
Find the backup you need using the backup creation time and cluster ID. The ID column contains IDs in
<cluster_ID>:<backup_ID>format. -
Click
for the backup you need, then click Restore cluster. -
Set up the new cluster. You can select a folder for the new cluster from the Folder list.
-
To restore the cluster state to a specific point in time after the backup was created, configure Date and time of recovery (UTC) accordingly. You can either specify the date manually or select it using the date picker.
If you leave this setting as is, the cluster will be restored to the state when the backup was completed.
-
Click Restore cluster.
Managed Service for PostgreSQL will start creating a cluster from the backup.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the cluster will be restored to the same folder where the backup is located. To restore the cluster to a different folder, specify its ID in the --folder-id option.
To restore a cluster from a backup:
-
View the description of the CLI command for restoring a PostgreSQL cluster:
yc managed-postgresql cluster restore --help -
Get the list of available PostgreSQL cluster backups:
yc managed-postgresql backup list+--------------------------+---------------------+----------------------+---------------------+ | ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT | +--------------------------+---------------------+----------------------+---------------------+ | c9qlk4v13uq7********:... | 2020-08-10 12:00:00 | c9qlk4v13uq7******** | 2020-08-10 11:55:17 | | ... | +--------------------------+---------------------+----------------------+---------------------+The
CREATED ATcolumn in the list of available backups shows the backup completion time inyyyy-mm-dd hh:mm:ssformat (2020-08-10 12:00:00in the example above). You can restore your cluster to the state it was in at any point in time after the backup was created. -
Make the following request to create a cluster from a backup:
yc managed-postgresql cluster restore \ --backup-id=<backup_ID> \ --time=<time> \ --name=<cluster_name> \ --environment=<environment> \ --network-name=<network_name> \ --host zone-id=<availability_zone>,` `subnet-name=<subnet_name>,` `assign-public-ip=<allow_public_access_to_host> \ --resource-preset=<host_class> \ --disk-size=<storage_size_in_GB> \ --disk-type=<disk_type>Where:
-
--backup-id: Backup ID. -
--time: Point in time to restore the PostgreSQL cluster to, inyyyy-mm-ddThh:mm:ssZformat. -
--name: Cluster name. -
--environment: Environment:PRESTABLE: For testing purposes. The prestable environment is similar to the production environment and is also covered by an SLA. However, it receives new features, improvements, and bug fixes earlier. In the prestable environment, you can test new versions for compatibility with your application.PRODUCTION: For stable versions of your applications.
-
--network-name: Network name. -
--host: Host settings:-
zone-id: Availability zone. -
subnet-name: Subnet name. You must specify this setting if the selected availability zone has more than one subnet. -
assign-public-ip: Flag to add if public access to the host is required (trueorfalse).
-
-
--resource-preset: Host class. -
--disk-size: Storage size, in GB. -
--disk-type: Disk type:network-hddnetwork-ssdlocal-ssdnetwork-ssd-nonreplicated*network-ssd-io-m3
-
Use Terraform to restore:
- Existing cluster from a backup.
- Cluster created and then deleted via the management console, CLI, or API.
Note
The cluster will be restored to the folder specified by its folder_id in the provider settings.
You will need the backup ID for the restoration. Get a list of available PostgreSQL cluster backups using the CLI:
yc managed-postgresql backup list
+--------------------------+---------------------+----------------------+---------------------+
| ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT |
+--------------------------+---------------------+----------------------+---------------------+
| c9qlk4v13uq7********:... | 2020-08-10 12:00:00 | c9qlk4v13uq7******** | 2020-08-10 11:55:17 |
| ... |
+--------------------------+---------------------+----------------------+---------------------+
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 timeouts section 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
}
}
To restore an existing cluster from a backup:
-
Create a Terraform configuration file for the new cluster.
Do not specify database (
yandex_mdb_postgresql_database) and user (yandex_mdb_postgresql_user) resources as they will be restored from the backup. -
Add the
restoresection to the configuration file:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... restore { backup_id = "<backup_ID>" time = "<time>" } }Where:
backup_id: Backup ID.time: Point in time to restore the PostgreSQL cluster to, starting from the selected backup's creation time. Format:yyyy-mm-ddThh:mm:ss.
Note
If you omit the
timesetting, the cluster will be restored to the backup’s completion time. -
Make sure the settings are correct.
-
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 updating the resources.
-
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.
-
-
Terraform will create a copy of the existing cluster. The databases and users will be deployed from the selected backup.
To restore a previously deleted cluster from a backup:
-
Create a Terraform configuration file for the new cluster.
Do not specify database (
yandex_mdb_postgresql_database) and user (yandex_mdb_postgresql_user) resources as they will be restored from the backup. -
In this configuration file, add the
restoresection with the name of the backup for restoration:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... restore { backup_id = "<backup_ID>" } }Where
backup-idis the ID of the deleted cluster’s backup. -
Make sure the settings are correct.
-
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 updating the resources.
-
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.
-
-
Terraform will create the new cluster. The databases and users will be deployed from the backup.
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Create a file named
body.jsonand paste the following code into it:{ "backupId": "<backup_ID>", "time": "<time>", "folderId": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "networkId": "<network_ID>", "configSpec": { "version": "<PostgreSQL_version>", "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } }, "hostSpecs": [ { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "assignPublicIp": <allow_public_access_to_host> } ] }Where:
-
backupId: Backup ID. You can get it from the backup list. -
time: Point in time to restore the PostgreSQL cluster to, inyyyy-mm-ddThh:mm:ssZformat. -
folderId: ID of the target folder to restore the cluster. You can get the folder ID with the list of folders in the cloud. -
name: Cluster name. -
environment: Environment:PRESTABLE: For testing purposes. The prestable environment is similar to the production environment and is also covered by an SLA. However, it receives new features, improvements, and bug fixes earlier. In the prestable environment, you can test new versions for compatibility with your application.PRODUCTION: For stable versions of your applications.
-
networkId: Network ID. -
configSpec: Cluster settings:-
version: PostgreSQL version. -
resources: Cluster resources:resourcePresetId: Host class.diskSize: Disk size, in bytes.diskTypeId: Disk type.
-
-
hostSpecs: Cluster host settings as an array of elements, one per host. Each element has the following structure:zoneId: Availability zone.subnetId: Subnet ID.assignPublicIp: Permission to connect to the host from the internet,trueorfalse.
-
-
Call the Cluster.Restore method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters:restore' \ --data "@body.json" -
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it in 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. -
Create a file named
body.jsonand paste the following code into it:{ "backup_id": "<backup_ID>", "time": "<time>", "folder_id": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "network_id": "<network_ID>", "config_spec": { "version": "<PostgreSQL_version>", "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } }, "host_specs": [ { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "assign_public_ip": <allow_public_access_to_host> } ] }Where:
-
backup_id: Backup ID. You can get it with the list of backups. -
time: Point in time to restore the PostgreSQL cluster to, inyyyy-mm-ddThh:mm:ssZformat. -
folder_id: ID of the target folder to restore the cluster. You can request the ID with the list of folders in the cloud. -
name: Cluster name. -
environment: Environment:PRESTABLE: For testing purposes. The prestable environment is similar to the production environment and is also covered by an SLA. However, it receives new features, improvements, and bug fixes earlier. In the prestable environment, you can test new versions for compatibility with your application.PRODUCTION: For stable versions of your applications.
-
network_id: Network ID. -
config_spec: Cluster settings:-
version: PostgreSQL version. -
resources: Cluster resources:resource_preset_id: Host class.disk_size: Disk size, in bytes.disk_type_id: Disk type.
-
-
host_specs: Cluster host settings as an array of elements, one per host. Each element has the following structure:zone_id: Availability zone.subnet_id: Subnet ID.assign_public_ip: Permission to connect to the host from the internet,trueorfalse.
-
-
Call the ClusterService.Restore method, e.g., via the following gRPCurl
request: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 @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.Restore \ < body.json -
Check the server response to make sure your request was successful.
Creating a backup
- Go to Managed Service for PostgreSQL.
- Click the name of your cluster and select the Backups tab.
- Click
Create backup.
This will initiate creating a backup without any additional confirmation.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To create a cluster backup:
-
View the description of the CLI command for creating a PostgreSQL backup:
yc managed-postgresql cluster backup --help -
Send a request to create a cluster backup by specifying the cluster name or ID:
yc managed-postgresql cluster backup my-pg-clusterYou can get the cluster name and ID from the list of clusters.
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.Backup method, e.g., via the following cURL
request: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>:backup'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 in 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.Backup method, for instance, via the following gRPCurl
request: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.BackupYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Warning
While you are creating a backup, the cluster performance may degrade.
Getting a list of backups
To get a list of cluster backups:
- Go to Managed Service for PostgreSQL.
- Click the name of your cluster and select the Backups tab.
To get a list of all backups in your folder:
- Go to Managed Service for PostgreSQL.
- Select the Backups tab.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To get a list of PostgreSQL cluster backups available in the default folder, run this command:
yc managed-postgresql backup list
+--------------------------+---------------------+----------------------+---------------------+
| ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT |
+--------------------------+---------------------+----------------------+---------------------+
| c9qlk4v13uq7********:... | 2020-08-10 12:00:00 | c9qlk4v13uq7******** | 2020-08-10 11:55:17 |
| c9qpm90p3pcg********:... | 2020-08-09 22:01:04 | c9qpm90p3pcg******** | 2020-08-09 21:30:00 |
+--------------------------+---------------------+----------------------+---------------------+
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
To get a list of cluster backups:
-
Call the Cluster.ListBackups method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/backups'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.
-
-
To get a list of backups for all clusters in a folder:
-
Call the Backup.List method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/backups' \ --url-query folderId=<folder_ID>You can get the folder ID with the list of folders in the cloud.
-
Check the server response to make sure your request was successful.
-
-
Get an IAM token for API authentication and put it in 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. -
To get a list of cluster backups:
-
Call the ClusterService.ListBackups method, e.g., via the following gRPCurl
request: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.ListBackupsYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
-
To list backups for all clusters in your folder:
-
Call the BackupService.List method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/backup_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "folder_id": "<folder_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.BackupService.ListYou can get the folder ID with the list of folders in the cloud.
-
Check the server response to make sure your request was successful.
-
Getting backup information
To get backup details for an existing cluster:
- Go to Managed Service for PostgreSQL.
- Click the name of your cluster and select the Backups tab.
To get backup details for a previously deleted cluster:
- Go to Managed Service for PostgreSQL.
- Select the Backups tab.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To get backup details for a PostgreSQL cluster, run this command:
yc managed-postgresql backup get <backup_ID>
You can get the backup ID with the list of backups.
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Backup.Get method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/backups/<backup_ID>'You can get the backup ID with the list of backups.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it in 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 BackupService.Get method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/backup_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "backup_id": "<backup_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.BackupService.GetYou can get the backup ID with the list of backups.
-
Check the server response to make sure your request was successful.
Setting the backup start time
In the management console, you can set the backup start time when creating or updating a cluster.
To set the backup start time, use the --backup-window-start option. You must specify the time in HH:MM:SS format.
yc managed-postgresql cluster create \
--cluster-name <cluster_name> \
--environment <environment> \
--network-name <network_name> \
--host zone-id=<availability_zone>,subnet-id=<subnet_ID> \
--resource-preset <host_class> \
--user name=<username>,password=<user_password> \
--database name=<DB_name>,owner=<DB_owner_name> \
--disk-size <storage_size_in_GB>
--backup-window-start 10:00:00
Where environment is the environment, either prestable or production.
To change the backup start time for an existing cluster, use the update command:
yc managed-postgresql cluster update \
--cluster-name <cluster_name> \
--backup-window-start 11:25:00
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
For a complete list of Managed Service for PostgreSQL cluster configuration fields you can update, see this Terraform provider guide.
-
Add the
backup_window_startblock to theconfigsection of the Managed Service for PostgreSQL cluster description:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... config { ... backup_window_start { hours = <hour> minutes = <minute> } ... } ...Where:
hours: Backup start hour (UTC).minutes: Backup start minute (UTC).
-
Make sure the settings are correct.
-
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 updating the resources.
-
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 in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.Update method and send the following request, e.g., via cURL
: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.backupWindowStart", "configSpec": { "backupWindowStart": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" } } }'Where:
-
updateMask: Comma-separated string of settings you want to update.Here, we provide only one setting.
-
configSpec.backupWindowStart: Backup window settings.In this setting, specify the backup start time. Allowed values:
hours: Between0and23hours.minutes: Between0and59minutes.seconds: Between0and59seconds.nanos: Between0and999999999nanoseconds.
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 in 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. -
Use the ClusterService.Update call and send the following request, e.g., via gRPCurl
: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.backup_window_start" ] }, "config_spec": { "backup_window_start": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" } } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateWhere:
-
update_mask: List of parameters to update as an array of strings (paths[]).Here, we provide only one setting.
-
config_spec.backup_window_start: Backup window settings.Here, specify the backup start time. Allowed values:
hours: Between0and23hours.minutes: Between0and59minutes.seconds: Between0and59seconds.nanos: Between0and999999999nanoseconds.
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.
Setting a retention period for automatic backups
You can set the retention period for automatic backups when you create or update the cluster via the management console
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To set the retention period for automatic backups, provide the required value for the --backup-retain-period-days argument of the cluster update command:
yc managed-postgresql cluster update <cluster_name_or_ID> \
--backup-retain-period-days=<retention_period_in_days>
Allowed values range from 7 to 60. The default value is 7.
You can get the cluster ID and name with the list of clusters in the folder.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
For a complete list of Managed Service for PostgreSQL cluster configuration fields you can update, see this Terraform provider guide.
-
Add the
backup_retain_period_daysblock to theconfigsection of the Managed Service for PostgreSQL cluster description:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... config { ... backup_retain_period_days = <retention_period_in_days> } ... } ...Where
backup_retain_period_daysis the automatic backup retention period.Allowed values range from
7to60. The default value is7. -
Make sure the settings are correct.
-
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 updating the resources.
-
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 in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.Update method and send the following request, e.g., via cURL
: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.backupRetainPeriodDays", "configSpec": { "backupRetainPeriodDays": <retention_period_in_days> } }'Where:
-
updateMask: Comma-separated string of settings you want to update.Here, we provide only one setting.
-
configSpec.backupRetainPeriodDays: Automatic backup retention period.The valid values range from
7to60. The default value is7.
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 in 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. -
Use the ClusterService.Update call and send the following request, e.g., via gRPCurl
: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.backup_retain_period_days" ] }, "config_spec": { "backup_retain_period_days": <retention_period_in_days> } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.ClusterService.UpdateWhere:
-
update_mask: List of parameters to update as an array of strings (paths[]).Here, we provide only one setting.
-
config_spec.backup_retain_period_days: Automatic backup retention period.Allowed values range from
7to60. The default value is7.
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.
Deleting a backup
You can only delete backups that were created manually.
- Go to Managed Service for PostgreSQL.
- Select the Managed Service for PostgreSQL cluster whose backup you want to delete.
- In the left-hand panel, select Backups.
- Click
next to the backup you want to delete. - Select Delete backup.
- Confirm deletion and click Delete.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To delete a backup:
-
View the description of the CLI command for deleting a PostgreSQL cluster backup:
yc managed-postgresql backup delete --help -
Send a request to delete a backup by specifying the backup ID:
yc managed-postgresql backup delete <backup_ID>
You can get the backup ID with the list of backups.
-
Get an IAM token for API authentication and put it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Backup.Delete method, e.g., via the following cURL
request:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/backups/<backup_ID>'You can get the backup ID with the list of backups.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it in 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 BackupService.Delete method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/backup_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "backup_id": "<backup_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.postgresql.v1.BackupService.DeleteYou can get the backup ID with the list of backups.
-
Check the server response to make sure your request was successful.