This is the multi-page printable view of this section. .
Instance with S3
A regular (non-Patroni) instance archives WAL and takes its pgBackRest backups
to local disk by default. This page covers the opt-in alternative: send
both straight to the environment’s shared S3 repository
(backup.repo.s3 — MinIO, silo, rustfs, garage, AWS S3, …), chosen once at
pg create time.
HA clusters behave differently and are not the subject here: a Patroni stanza uses the S3 repo automatically whenever one is configured — see Backup → S3 Object Storage Repository and HA Cluster → S3 storage.
Prerequisite: the global S3 repo
backup-target: s3 instances do not carry their own endpoint or credentials —
they reference the single host-level backup.repo.s3 block in pg.yaml. The
S3 store normally lives on its own machine (e.g. a dedicated
pg addon install minio host), separate from the hosts running the pgcli
instances — the instance host only needs network reach to the endpoint plus
the store’s TLS trust anchor. Store host 192.0.2.9, instance host
192.0.2.10:
Cross-check the fingerprint against the store host (it’s trust-on-first-use), then register the repo — a complete block is endpoint + bucket + access_key + secret_key:
(A passing shell with history expansion or shared logs may prefer editing
backup.repo.s3.secret_key into pg.yaml instead of the flag.) The rest of
the mechanics are identical to the Patroni case —
Backup → S3 Object Storage Repository
covers HTTPS-mandatory, verify_tls, and publicly-caught endpoints (real AWS
S3 just omit --s3-ca-file). The S3 block must be complete — an
incomplete repo is rejected at pg create, pg start, and pg backup setup,
never silently downgraded to local. And it is per host: on a multi-host
setup, each host that runs instances or promotes replicas configures its own
backup.repo.s3 the same way (cross-host HA clusters instead distribute the
CA and SSH public keys via etcd — see the Backup doc’s “Cross-host HA” bullet).
Create an instance on S3
--backup-target accepts local (default) and s3. The choice is recorded
per instance (instances.<name>.pitr.backup_target: s3) and survives reloads;
a local instance simply omits the key.
What the flag changes underneath: the instance’s stanza in the shared backup
container gets a per-stanza repo1-type=s3 override (endpoint, bucket,
region, path, credentials, CA), and so does the hostless conf inside the PG
container that archive-push runs from. The [global] repo stays local, so
the two target kinds never interfere.
No dual-write. An s3-target stanza writes only to S3 — backups and WAL never touch the local repository, and no copy is kept on either side. If you later aim the instance at a different repo, nothing migrates: the stanza starts a fresh backup chain from zero, and old local backups simply age out.
The target is chosen at create time. There is no switch for a running instance — to move one, create a new instance with the desired target and migrate data as usual.
Local and S3 instances coexist
One environment, one backup container, mixed targets:
Retention, compression, and the shared stanza lifecycle (stanza-create,
stanza-upgrade, expiry) work identically for both — only the repository
bytes land in a different place. pg backup setup’s connectivity probe
prefers a stanza that really uses S3 whenever the repo is configured.
Replicas: no backups until promoted
A replica — same-host or cross-host — gets no backup configuration: PITR stays disabled while it streams from its primary, and archiving remains the primary’s job (the replica’s WAL arrives via streaming replication, and PITR on the primary covers it).
pg replica promote <name> decides the new primary’s backup target
automatically — before calling pg_promote():
| Situation | Result |
|---|---|
This host has a complete backup.repo.s3 |
promoted, backup target = s3 |
| No S3 repo (same-host or cross-host replica) | promoted, backup target = local |
backup.repo.s3 present but incomplete |
promotion aborted (fix the block, then re-run) |
So a cross-host replica with no S3 configured on this host behaves exactly
like a same-host one: it promotes to a local-backed primary and starts a
fresh backup chain here. Be aware that this new chain is unrelated to the old
primary’s repository — the WAL that preceded the promotion lives in the old
host’s repo, so you cannot PITR back through the failover point from this one.
If you want the promoted instance to continue on S3 instead, configure the repo
on this host first (the same pg backup fetch-ca +
pg backup setup --s3-* pair from the prerequisite section — the store is the
same remote machine), then promote and it resolves to s3:
After a successful promotion, stanza creation, archive_command wiring and
the PostgreSQL restart proceed exactly as the failover doc
describes — with the target the table above resolved.
Restore and PITR
Nothing to change: pg restore --time ... on an s3-target instance reads
backups and WAL from S3 through the same stanza, and pgBackRest fetches via
the per-stanza override. The temporary restore container gets the CA mount
automatically when ca_file is set. Private-CA stores work because the CA
certificate is bind-mounted read-only to /etc/pgbackrest/ca.crt in both the
PG container (archive-push) and the restore container — pg adds the mount
when creating containers, and pg start recreates an older PG container
that predates the mount (data lives in volumes, so the stop-rm-create is
lossless).
See also
- Backup — shared backup container, snapshots, the S3 repo block
- Restore — PITR workflow and time formats
- Failover —
pg replica promotestep by step - HA Cluster → S3 storage — the Patroni equivalent