Recovery v1
Warning
With the deprecation of native Barman Cloud support in EDB Postgres for Kubernetes in favor of the Barman Cloud Plugin, this page—and the backup and recovery documentation—may undergo changes before the official release of version 1.26.0.
In PostgreSQL terminology, recovery is the process of starting a PostgreSQL instance using an existing backup. The PostgreSQL recovery mechanism is very solid and rich. It also supports point-in-time recovery (PITR), which allows you to restore a given cluster up to any point in time, from the first available backup in your catalog to the last archived WAL. (The WAL archive is mandatory in this case.)
In EDB Postgres for Kubernetes, you can't perform recovery in place on an existing cluster. Recovery is instead a way to bootstrap a new Postgres cluster starting from an available physical backup.
Note
For details on the bootstrap
stanza, see
Bootstrap.
The recovery
bootstrap mode lets you create a cluster from an existing
physical base backup. You then reapply the WAL files containing the REDO log
from the archive.
WAL files are pulled from the defined recovery object store.
Base backups can be taken either on object stores or using volume snapshots.
Info
Starting with version 1.25, EDB Postgres for Kubernetes includes experimental support for backup and recovery using plugins, such as the Barman Cloud plugin.
You can achieve recovery from a recovery object store in two ways:
- We recommend using a recovery object store, that is, a backup of another cluster
created by Barman Cloud and defined by way of the
barmanObjectStore
option in theexternalClusters
section. - Alternatively, you can use an existing
Backup
object in the same namespace.
Both recovery methods enable either full recovery (up to the last available WAL) or up to a point in time. When performing a full recovery, you can also start the cluster in replica mode (see replica clusters for reference).
Important
If using replica mode, make sure that the PostgreSQL configuration
(.spec.postgresql.parameters
) of the recovered cluster is compatible with
the original one from a physical replication standpoint.
For recovery using volume snapshots:
- Use a consistent set of
VolumeSnapshot
objects that all belong to the same backup and are identified by the samek8s.enterprisedb.io/cluster
andk8s.enterprisedb.io/backupName
labels. Then, recover through thevolumeSnapshots
option in the.spec.bootstrap.recovery
stanza, as described in Recovery fromVolumeSnapshot
objects.
Recovery from an object store
You can recover from a backup created by Barman Cloud and stored on a supported
object store. After you define the external cluster, including all the required
configuration in the barmanObjectStore
section, you need to reference it in
the .spec.recovery.source
option.
This example defines a recovery object store in a blob container in Azure:
apiVersion: postgresql.k8s.enterprisedb.io/v1 kind: Cluster metadata: name: cluster-restore spec: [...] superuserSecret: name: superuser-secret bootstrap: recovery: source: clusterBackup externalClusters: - name: clusterBackup barmanObjectStore: destinationPath: https://STORAGEACCOUNTNAME.blob.core.windows.net/CONTAINERNAME/ azureCredentials: storageAccount: name: recovery-object-store-secret key: storage_account_name storageKey: name: recovery-object-store-secret key: storage_account_key wal: maxParallel: 8
The previous example assumes that the application database and its owning user
are named app
by default. If the PostgreSQL cluster being restored uses
different names, you must specify these names before exiting the recovery phase,
as documented in "Configure the application database".
Important
By default, the recovery
method strictly uses the name
of the
cluster in the externalClusters
section as the name of the main folder
of the backup data within the object store. This name is normally reserved
for the name of the server. You can specify a different folder name
using the barmanObjectStore.serverName
property.
Note
This example takes advantage of the parallel WAL restore feature, dedicating up to 8 jobs to concurrently fetch the required WAL files from the archive. This feature can appreciably reduce the recovery time. Make sure that you plan ahead for this scenario and correctly tune the value of this parameter for your environment. It will make a difference when you need it, and you will.
Recovery from VolumeSnapshot
objects
Warning
When creating replicas after recovering the primary instance from
the volume snapshot, the operator might end up using pg_basebackup
to synchronize them. This behavior results in a slower process, depending
on the size of the database. This limitation will be lifted in the future when
support for online backups and PVC cloning are introduced.
EDB Postgres for Kubernetes can create a new cluster from a VolumeSnapshot
of a PVC of an
existing Cluster
that's been taken using the declarative API for volume
snapshot backups. You must specify the name of the
snapshot, as in the following example:
apiVersion: postgresql.k8s.enterprisedb.io/v1 kind: Cluster metadata: name: cluster-restore spec: [...] bootstrap: recovery: volumeSnapshots: storage: name: <snapshot name> kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io
In case the backed-up cluster was using a separate PVC to store the WAL files, the recovery must include that too:
apiVersion: postgresql.k8s.enterprisedb.io/v1 kind: Cluster metadata: name: cluster-restore spec: [...] bootstrap: recovery: volumeSnapshots: storage: name: <snapshot name> kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io walStorage: name: <snapshot name> kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io
The previous example assumes that the application database and its owning user
are named app
by default. If the PostgreSQL cluster being restored uses
different names, you must specify these names before exiting the recovery phase,
as documented in "Configure the application database".
Warning
If bootstrapping a replica-mode cluster from snapshots, to leverage snapshots for the standby instances and not just the primary, we recommend that you:
- Start with a single instance replica cluster. The primary instance will be recovered using the snapshot, and available WALs from the source cluster.
- Take a snapshot of the primary in the replica cluster.
- Increase the number of instances in the replica cluster as desired.
Recovery from a Backup
object
If a Backup
resource is already available in the namespace in which you need
to create the cluster, you can specify the name using
.spec.bootstrap.recovery.backup.name
, as in the following example: