Managing disk space
When the storage is more than 97% full, the host automatically switches to read-only mode.
To avoid issues with writing to the database, use one of the following methods:
-
Set up alerts in Yandex Monitoring to monitor storage utilization.
-
Manually get the cluster out of the read-only mode and free up the storage space by deleting some data.
-
Increase the storage size to automatically disable the read-only mode.
Set up alerts in Yandex Monitoring
-
Go to the folder page and select Monitoring.
-
Select Managed Service for PostgreSQL.
-
Create an alert with the following properties:
-
Metrics: Set the following metric parameters:
-
Cloud
-
Folder
-
Managed Service for PostgreSQL service
-
Managed Service for PostgreSQL cluster ID
You can get the cluster ID with a list of clusters in the folder.
-
disk.free_bytes
label
-
-
Alert condition: Set the
Less than or equals
condition for free disk space utilization percentage to trigger the alert:- Aggregation function:
Minimum
(minimum metric value for the period). - Warning:
90
(90% of storage size). - Alarm:
95
(95% of storage size). - Evaluation window: Preferred period to update the metric value.
- Aggregation function:
-
Add the previously created notification channel.
-
Manually get the cluster out of the read-only mode
Alert
Do not allow free disk space to drop to zero during the following actions. Otherwise, since the fail-safe is disabled, PostgreSQL will crash and the cluster will stop working.
To disable the read-only mode:
-
Connect to the database in any appropriate way.
-
Open a transaction and run the following command inside it:
SET LOCAL transaction_read_only TO off;
-
As part of the same transaction, delete the data you do not need using the
DROP
orTRUNCATE
operators. Do not use theDELETE
operator, as it marks rows as deleted but does not physically delete them from the database. -
Commit the transaction and restart all connections to the database.
For example, if your database contains a table called
ExcessDataTable1
that you no longer need, delete it with the following transaction:
BEGIN; SET LOCAL transaction_read_only TO off; DROP TABLE ExcessDataTable1; COMMIT;
Increasing storage size
Note
Some PostgreSQL settings depend on the storage size.
Make sure the cloud has enough quota to increase the storage size. Open the cloud's Quotas
Warning
- You cannot decrease the storage size.
- While resizing the storage, cluster hosts will be unavailable.
To increase the cluster storage size:
- Go to the folder page and select Managed Service for PostgreSQL.
- Select the cluster and click
Edit cluster in the top panel. - Under Size of storage, specify the required value.
- Click Save changes.
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 increase the cluster storage size:
-
View a description of the update cluster CLI command:
yc managed-postgresql cluster update --help
-
Specify the required storage in the cluster update command (it must be at least as large as
disk_size
in the cluster properties):yc managed-postgresql cluster update <cluster_name_or_ID> \ --disk-size <storage_size_in_GB>
To increase the cluster storage size:
-
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
disk_size
attribute value underconfig.resources
:resource "yandex_mdb_postgresql_cluster" "<cluster_name>" { ... config { resources { disk_size = <storage_size_in_GB> ... } } }
-
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 increase the cluster storage size, use the update REST API method for the Cluster resource or the ClusterService/Update 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. - New storage size in the
configSpec.resources.diskSize
parameter. - List of settings to update (in this case,
configSpec.resources.diskSize
) in theupdateMask
parameter.
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).
Setting up automatic increase of storage size
Note
Some PostgreSQL settings depend on the storage size.
Make sure the cloud has enough quota to increase the storage size. Open the cloud's Quotas
Warning
- You cannot decrease the storage size.
- While resizing the storage, cluster hosts will be unavailable.
-
Go to the folder page and select Managed Service for PostgreSQL.
-
Select the cluster and click Edit cluster in the top panel.
-
Under Automatic increase of storage size:
-
In the Increase size field, set the storage utilization percentage to trigger storage increase. You can configure the increase to take place:
- During the next maintenance window.
- Right away.
You can enable both rules, but the threshold for immediate increase should be higher than that for increase during the maintenance window.
-
In the Maximum storage size field, specify the maximum storage size that can be set if increasing storage size automatically.
-
-
Click Save changes.
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 set up automatic increase of storage size:
-
View a description of the update cluster CLI command:
yc managed-postgresql cluster update --help
-
Set the maximum storage size and conditions for its increase in the update cluster command.
Make sure the maximum storage size is greater than the
disk_size
value in the cluster properties. The percentage for immediate increase should be higher than that for increase during the next maintenance window.yc managed-postgresql cluster update <cluster_ID_or_name> \ --disk-size-autoscaling disk-size-limit=<max_storage_size_in_bytes>,` `planned-usage-threshold=<percentage_for_scheduled_increase>,` `emergency-usage-threshold=<percentage_for_immediate_increase>
To enable automatic increase of storage size, use the update REST API method for the Cluster resource or the ClusterService/Update gRPC API call and provide the following in the request:
-
Storage utilization percentage to trigger a storage increase in the next maintenance window, in the
configSpec.diskSizeAutoscaling.plannedUsageThreshold
parameter.Use a value between
0
and100
%. The default value is0
(automatic expansion is disabled). -
Storage utilization percentage to trigger an immediate storage increase, in the
configSpec.diskSizeAutoscaling.emergencyUsageThreshold
parameter.Use a value between
0
and100
%. The default value is0
(automatic expansion is disabled). If the value is greater than0
, it cannot be less than the value provided in theconfigSpec.diskSizeAutoscaling.plannedUsageThreshold
parameter. -
Maximum storage size, in bytes, that can be set upon reaching one of the specified utilization percentages, in the
configSpec.diskSizeAutoscaling.diskSizeLimit
parameter.
If you have set up the storage size to increase within the maintenance window, set up a schedule for the maintenance window.
As soon as one of the specified conditions is met, the storage size will be increased:
- For network HDDs and SSDs, by the higher value of the two: 20 GB or 20% of the current disk size.
- For non-replicated SSDs, by 93 GB.
- For local SSDs:
- In an Intel Broadwell or Intel Cascade Lake cluster, by 100 GB.
- In an Intel Ice Lake cluster, by 368 GB.
The storage size will be automatically increased on repeated triggers until it reaches the specified maximum. After that, you can specify a new maximum storage size manually.