Skip to content

Support backing up PostgreSQL from a standby (pgBackRest backup-standby) #960

Description

@marf

Summary

The PostgreSQL provider always configures pgBackRest to take backups from the primary. There is no way, through the DatabaseCluster API or otherwise, to make Everest use pgBackRest's backup-standby option so that the data is read from a replica instead.

Reading backups from a standby is a pgBackRest best practice: it offloads the primary (no extra read I/O / load on the write node during a backup) and is the recommended setup for any cluster with one or more replicas. The underlying Percona/Crunchy operator already supports it via spec.backups.pgbackrest.global (backup-standby: "y"), but Everest neither sets it nor exposes it, and it reconciles the PerconaPGCluster back to no standby config.

Current behavior

internal/controller/everest/providers/pg/applier.goreconcilePGBackupsSpec() builds pgv2.Backups and assigns newBackups.PGBackRest.Global = pgBackrestGlobal, but never includes backup-standby. The DatabaseCluster.spec.backup schema only exposes pitr and schedules, so there's no user-facing way to opt in either.

Proposed change

PGBackRest.Global maps 1:1 to spec.backups.pgbackrest.global, which is passed straight to pgBackRest, and the operator already configures every instance as a pg-host (so pgBackRest can auto-detect primary vs standby). The change is small:

Option A — minimal (always back up from standby when replicas exist):

// reconcilePGBackupsSpec(), right after: newBackups.PGBackRest.Global = pgBackrestGlobal
if newBackups.PGBackRest.Global == nil {
    newBackups.PGBackRest.Global = map[string]string{}
}
newBackups.PGBackRest.Global["backup-standby"] = "y"

Option B — opt-in field (preferred): add DatabaseCluster.spec.backup.backupFromStandby *bool (default false) and gate the above on it.

Caveat

backup-standby=y requires at least one standby host, so it should be skipped for single-instance clusters.

I have Option A running on a fork (PG 17.9 / operator 2.9.0 / pgBackRest 2.58, Everest 1.15.2) and it works as expected — backups read from a replica. Happy to open a PR for Option B if the maintainers agree on the API shape.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions