Backups

Backups are enabled by default. The backup mechanism and configuration options depend on the deployment method.

CloudNativePG (default)

CloudNativePG instances use the Barman Cloud Plugin for backups. Backups are stored in an object store and support Point-in-Time Recovery (PITR).

A backup is taken daily at a randomly chosen time between 22:00 and 4:00 by default. You can specify a different backup time and interval using the following configuration:

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  parameters:
    ...
    backup:
      schedule: 0 22 * * * (1)
    ...
1 The schedules for your backups.

Retention

By default, backups are retained for 6 days.

To change the retention period, configure the backup.retention field:

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  parameters:
    ...
    backup:
      retention: 14 (1)
    ...
1 Number of days to retain backups (default: 6).

WAL archive retention is tied to the base backup retention window. Barman Cloud automatically keeps all WAL segments needed to restore any backup within the retention period. WAL retention cannot be configured independently.

Point in Time interval

By default, the WALs (Write Ahead Logs) are archived once a WAL file is completed (16Mb) or after archive_timeout (5 minutes by default), whichever comes first. This gives a RPO of at most 5 minutes.

To decrease or increase the RPO, override the archive_timeout setting:

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  parameters:
    ...
    service:
      pgSettings:
        archive_timeout: "60" (1)
    ...
1 Amount of time between WAL archives in seconds (default: 300)
When archive_timeout triggers early WAL rotation, PostgreSQL pads the segment to 16 MB before handing it to barman-cloud. Barman Cloud then compresses it with gzip before uploading to the object store. On low-activity systems, the compressed archive is typically well under 1 MB, so a short archive_timeout has minimal impact on object store usage.

Disable Backups

To disable backups, set the backup.enabled field to false. This will also disable WAL archiving:

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  parameters:
    ...
    backup:
      enabled: false
    ...

If backups were previously enabled, existing backups will be retained until their retention period expires.

Disabling backups is meant for test instances only. It is not recommended to disable backups for production instances.

Backup in Multi-Instance Setups

When a VSHNPostgreSQL instance is configured with multiple instances, backups are always taken from the primary instance.

PostgreSQL’s online backup mechanism is used, which means replication to standby instances is not interrupted or paused during a backup.

WAL archiving is also handled exclusively by the primary instance. Standby instances do not archive WAL independently, which prevents duplicate segments in the object store.

StackGres

This section only applies to StackGres-based instances (with compositionRef: vshnpostgres.vshn.appcat.vshn.io).

StackGres instances use pgBackRest for backups, which supports Point-in-Time Recovery. This approach allows making a backup of an online database with minimum performance hit. It also guarantees that the changes made to the data during the backup process will also end up in the backup files.

A backup is taken daily at a randomly chosen time between 22:00 and 4:00 by default. You can specify a different backup time and interval using the following configuration:

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  compositionRef:
    name: vshnpostgres.vshn.appcat.vshn.io
  parameters:
    ...
    backup:
      schedule: 0 22 * * * (1)
    ...
1 The schedules for your backups.

Point in Time interval

By default, the WALs (Write Ahead Logs) will be shipped every time a WAL file has been completed. They grow to 16Mb before being considered completed and be archived to the backup object store. This will result in variable RPO times.

If fixed RPO time is required, the archive_timeout setting can be set. It will force an archive of the WAL files every given interval.

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  parameters:
    ...
    service:
      pgSettings:
        archive_timeout: "300" (1)
    ...
1 Amount of time between WAL archives in seconds
When archive_timeout triggers early WAL rotation, PostgreSQL pads the segment to 16 MB before archiving. pgBackRest compresses the segment before uploading to the object store, so on low-activity systems the stored archive is typically well under 1 MB. A short archive_timeout therefore has minimal impact on object store usage.

Disable Backups

To disable backups, set the backup.enabled field to false. This will also disable WAL archiving:

apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNPostgreSQL
metadata:
  name: pgsql-app1-prod
  namespace: <your-namespace>
spec:
  parameters:
    ...
    backup:
      enabled: false
    ...

If backups were previously enabled, existing backups will be retained until their retention period expires.

Disabling backups is meant for test instances only. It is not recommended to disable backups for production instances.

Listing Backups

Get an overview of all backups performed of your database instance:

$ kubectl -n <your-namespace> get vshnpostgresbackups
BACKUP NAME                                 DATABASE INSTANCE   STORED TIME               STATUS     AGE
pgsql-app1-prod-pk8k4-2023-03-05-13-05-00   pgsql-app1-prod     2023-03-05T13:05:15.755Z  Completed  38s
pgsql-app1-dev-pk8k4-2023-03-01-16-52-11    pgsql-app1-dev                                Failed     28s
The list will show all backups from all instances in this namespace. In the example above there are two database instances with one backup each.

Backup Details

Learn more about a chosen backup:

$ kubectl -n <your-namespace> get vshnpostgresbackups pgsql-app1-prod-pk8k4-2023-03-05-13-05-00 -oyaml
apiVersion: api.appcat.vshn.io/v1
kind: VSHNPostgresBackup
metadata:
  name: pgsql-app1-prod-pk8k4-2023-03-05-13-05-00 (1)
  namespace: <your-namespace>
status:
  databaseInstance: pgsql-app1-prod (2)
  process:
    failure: "" (3)
    jobPod: pgsql-app1-prod-pk8k4-backup-27967024-6xjpq
    status: Completed
    timing:
      end: "2023-03-05T13:05:15.61228Z"
      start: "2023-03-05T13:05:09.519369Z"
      stored: "2023-03-05T13:05:15.755Z" (4)
1 The name of the backup.
2 The name of the database instance of this backup.
3 A failure message if the backup job failed.
4 The date and time of the backup.