Recovering a cluster
If you have lost a PostgreSQL cluster in a project, you can restore it from a backup.
restoreClusterSpec property
When restoring from a backup, you can select a source of the cluster configuration (number of instances, storage size, PostgreSQL version, and so on), which is either the backup itself or the manifest:
-
restoreClusterSpec: true(default): Cluster configuration is restored from the backup. The restored cluster will inheritspec.instances,spec.storage,spec.version, and other settings from the original cluster at the time of backup. This property is optional in the manifest. -
restoreClusterSpec: false: Cluster configuration is sourced from your manifest. Data is restored from the selected backup, while the number of instances, storage size, PostgreSQL version, and other settings are defined in the manifest. Use this mode if you need to restore data into a cluster with a different configuration, e.g., fewer instances or reduced disk size.
This setting is defined in spec.bootstrap.recovery.restoreClusterSpec.
Using the CLI
-
Create a file of the
PostgresqlClusterresource, e.g., using thetouch postgresqlcluster-from-backup.yamlcommand. -
Open the file and paste the configuration for recovery:
From a backup (configuration sourced from a backup)From a backup with a custom configurationTo a specific point in time:Set the
spec.bootstrap.recovery.fromBackupproperty to the name of the backup to recover your cluster from. List of backups:kubectl get PostgresqlBackups -n <project_name>. The cluster configuration (instances, storage, version, and so on) will be sourced from the backup (default:restoreClusterSpec: true).apiVersion: postgresql.stackland.yandex.cloud/v1alpha1 kind: PostgresqlCluster metadata: name: cluster-restored annotations: pgcl.io/description: "PostgreSQL Cluster restored from backup" spec: bootstrap: recovery: fromBackup: cluster-backup backup: storage: type: stackland-storageSpecify
spec.bootstrap.recovery.fromBackupandspec.bootstrap.recovery.restoreClusterSpec: false. Define the cluster configuration (spec.instances,spec.storage,spec.version, and so on) in the manifest. Data will be restored from the backup, but the cluster will be recreated with the settings you defined in the manifest.apiVersion: postgresql.stackland.yandex.cloud/v1alpha1 kind: PostgresqlCluster metadata: name: cluster-restored-custom-spec annotations: pgcl.io/description: "PostgreSQL Cluster restored from backup with custom spec" spec: instances: 1 storage: size: 2Gi version: "17" bootstrap: recovery: fromBackup: cluster-backup restoreClusterSpec: false backup: storage: type: stackland-storageFor point-in-time recovery (PITR), specify the backup name (
PostgresqlBackup) to use inspec.bootstrap.recovery.fromBackup. List of backups:kubectl get PostgresqlBackups -n <project_name>. Usespec.bootstrap.recovery.recoveryTarget.targetTimeto set a restore timestamp in RFC3339 format.apiVersion: postgresql.stackland.yandex.cloud/v1alpha1 kind: PostgresqlCluster metadata: name: cluster-restored-from-pitr annotations: pgcl.io/description: "PostgreSQL Cluster restored with PITR" spec: instances: 1 storage: size: 2Gi version: "17" postgresConfiguration: logLevel: info bootstrap: recovery: fromBackup: cluster-backup recoveryTarget: targetTime: "2025-02-25T10:00:00Z" backup: storage: type: stackland-storage -
Apply the manifest:
kubectl apply -f postgresqlcluster-from-backup.yaml -n <project_name>. Optionally, you can specify the project name in themetadata.namespaceresource property and skip it in the command.
Using the management console
-
If you have not opened a project yet, select one.
-
In the left-hand menu, select PostgreSQL Clusters.
-
Go to the Backups tab.
-
Select a backup and click Recover from backup.
-
Check the cluster settings and modify them if required:
- Recovery time: Timestamp to recover your cluster up to.
- Cluster name: Only use lowercase letters, numbers, and hyphens.
- Number of instances: Number of cluster replicas.
- PostgreSQL version: Select from the list of available versions.
- Computing resources, where Limits is the upper limit and Requests is the lower limit.
- Storage, where Disk type is the storage class (
stackland-nvme,stackland-ssd,stackland-hdd,stackland-other). Learn more about storage classes in Disk subsystem. - Database: Section containing authentication credentials.
- Connection pooler: Handles writes and reads; used for all data-modifying operations and critical transactions.
- Backups: Settings for copying the database to an S3 bucket.
-
Click Create.
That is it! Your cluster has been recovered and now appears in the project's cluster list.