Why offsite and immutable PostgreSQL backups matter for recovery
A backup that sits next to the primary and can be deleted with the same credentials does not survive ransomware or operator error. High availability and replication protect against hardware failure, not against bad data. A standby faithfully applies a DROP TABLE or an encrypted overwrite, so the copy you need for recovery must be a separate, independently protected repository. Teams with recovery point and recovery time targets need this layer as soon as they accept that a compromised administrator account, a leaked cloud key or a misfired cleanup script could reach the database and its backups in one sweep.
PostgreSQL's continuous archiving model splits recovery into two parts. A base backup is a copy of the data directory taken while the server runs, and archived WAL files are the write-ahead log segments produced after that point. Restoring the base backup and replaying archived WAL up to a chosen moment gives point-in-time recovery. The recovery point is therefore set by how often WAL reaches the repository, and the recovery time is set by how fast the base backup and WAL can be fetched and replayed. Both halves must land in the offsite repository, or the restore has nothing to start from.
Immutability and separation are the controls that make the repository survive an attacker or a mistake. Confirm with your storage platform whether object lock, versioning and soft delete are available, whether retention can be set in governance or compliance mode, and whether the backup writer can delete objects at all. Keep backup credentials and the backup account separate from database and production cloud administrators. Because a fast local restore is also needed, plan a second repository close to the database for routine restores, and treat the offsite copy as the answer to the question of whether data survives an incident.
How the local and offsite repositories fit together
The diagram starts at the PostgreSQL primary, which ships WAL and base backups to a local repository on a backup host in the same site, so routine restores stay fast. A second copy goes to object storage in a separate account, where object lock and versioning keep prior copies intact even if the database host or its credentials are compromised. Check that the backup account's credentials cannot reach the database host, that restore operators hold their own access path, and that a restore from each repository has been tested.
Backup flow from the primary to a local and an offsite repository, with restore paths.
Which controls protect backups from which risk
Ransomware that encrypts the database server usually reaches the backup job too, because the job runs on the same machine with the same permissions. The controls that help are the ones that stop the attacker from changing or deleting copies that already exist, even when the attacker has the server's credentials. Object lock in write-once mode is the main answer, since it blocks overwrites and deletes until a retention period ends, but only if the bucket was created with it enabled.
- Object lock with a retention period: Copies written by the backup job cannot be altered or removed until the retention period expires, including by the job's own credentials.
- Separate writer identity: Give the backup job a credential that can put objects but cannot delete or change retention settings.
- Versioning: Keeps prior object versions so an overwrite can be reversed, which matters if lock is not applied to every prefix.
- Off-host transfer: Copies leave the database host quickly, so a host encrypted minutes after a backup still has a clean copy elsewhere.
- Not covered: Encryption of the live database itself, and data already corrupted before the backup ran. Confirm with your storage vendor how lock behaves on your object store and whether retention can be shortened by an administrator.
Check that an attacker holding the database host's credentials cannot delete a copy written yesterday.
A stolen access key for the backup repository lets an attacker read every copy and, if permissions are broad, destroy them. Separating credentials limits what one leaked secret can do. Repository encryption is the second layer: copies that are read without the repository key are unreadable, though this does not stop destruction.
- Least-privilege keys: Restore keys, backup-writer keys and administrative keys are separate, and only the restore path can read backups.
- Repository encryption: The backup tool encrypts data before upload, so bucket-level read access alone does not expose plaintext. Store the encryption passphrase outside the database host and outside the bucket.
- Short-lived or role-based credentials: Where the platform supports it, use federated or role-assumed access that expires, which narrows the window for a stolen key.
- Access logging: Enable object access logs and alert on reads or permission changes from unexpected identities.
- Not covered: A compromised key that holds administrative rights can disable object lock or delete the lock configuration, and encryption does not help if the passphrase is stored beside the copies. Confirm with the platform whether lock settings can be changed by any principal that holds administrative rights, and whether that action is itself logged.
Check that no single key can both read the repository and change its retention settings.
Most deletions are operator errors: a retention rule set too short, a cleanup script run against the wrong prefix, or a repository renamed during a migration. A malicious insider follows the same paths with more intent. Soft delete and versioning turn a deletion into a recoverable event, while retention rules control how long that recovery window lasts.
- Soft delete: Deleted objects are held for a set window and can be restored, which covers mistakes made by administrators as well as scripts.
- Versioning: Each change creates a new version, so an overwrite or delete marker can be reverted to the prior copy.
- Retention matched to policy: Set the retention period from your recovery and audit requirements, and record who approved it, so shortening it is a deliberate change.
- Two-person changes: Require review for retention, lifecycle and bucket policy changes, using your change process or the platform's approval features where they exist.
- Not covered: Deletion of the source data itself, which backups preserve only if the retention window is long enough to recover it. Confirm the lifecycle rules, soft delete window and version retention behavior on your platform, because these settings differ between providers.
Check that a deleted repository prefix can be recovered inside your stated retention period, and test it.
A cloud account can be suspended, compromised at the administrative level, or misconfigured, and a single region can be affected by an outage. A repository in the same account and region as the database protects against hardware loss but not against these events. Separate accounts and a second location address this threat, with trade-offs in cost, transfer and operational complexity.
- Separate account or tenancy: Store a copy in an account with its own administrators, billing and access policies, so one account's compromise does not reach both.
- Second region or site: Replicate or write to a location that does not share a failure domain with the primary, and confirm the provider's replication options.
- Local fast-restore repository: Keep a second repository close to the database for quick restores, while the off-site copy handles disaster cases.
- Documented access path: Keep break-glass credentials for the secondary account in a location that survives the loss of the primary identity provider.
- Not covered: Data-residency rules that restrict where copies may sit, and transfer delays when restoring a large repository across regions. Confirm residency requirements with your compliance team and measure restore time from the off-site copy, not only from the local one.
Check that a restore is possible when the primary cloud account is unavailable.
Configuration options and when each fits
This table compares the protection options for an off-site PostgreSQL backup repository, from object lock modes to a second local repository. Read each row as a trade-off: stronger immutability usually means less room to correct mistakes and tighter key and credential planning. Most teams combine a locked off-site copy with a faster local repository rather than choosing one option alone.
| Option | Retention and deletion | Key management and credential scope | Restore speed and fit |
|---|---|---|---|
| Object lock, governance mode | Retention applies, but users with a specific bypass permission can shorten or remove it. Useful when you need a guardrail against accidents and ransomware without hard lock-in. | Bypass permission should sit with a separate, tightly held role. Confirm exactly which permission your store checks. | Restores read the object directly, so speed depends on network path to the store, not on the lock mode. Good default for most teams that want recovery room. |
| Object lock, compliance mode | No user, including the account root, can shorten or remove the retention period before it expires. Strongest protection against an attacker with admin access. | Mistakes cannot be undone until expiry, so retention periods and lifecycle rules need review before go-live. Confirm how the store handles key rotation under lock. | Restore speed matches the object store path. Storage costs keep growing until expiry, so plan retention length against the copies you actually need. |
| Bucket versioning alone | Overwritten and deleted objects keep prior versions, but a user with delete rights can still remove versions unless other controls block it. Protects against simple overwrites, not determined deletion. | Versioning does not separate credentials. Pair it with a backup-only write role and a second account or credential that cannot delete versions. | Fast to restore a specific version. Version history grows with every backup run, so lifecycle rules for old versions must be designed and tested. |
| Soft delete, where supported | Deleted objects stay recoverable for a set window. Availability depends on the store, so confirm support for your platform before relying on it. | Recovery from soft delete usually needs a permission that the backup account itself should not hold. Keep that permission separate. | Recovery is quick for recent deletions. It does not protect against deliberate overwrites or long-running attacks that outlast the window. |
| Second local repository | Shorter retention, kept on hardware or a network path the object store credentials cannot reach. Typically holds the most recent full and incremental sets. | Uses its own credentials and host access, so an attacker with object store keys cannot touch it. Protect the host with the same rigor as the database. | Usually the fastest restore path for common incidents such as a bad release or dropped table. Not sufficient alone, because a site-level loss removes it too. |
How immutability and retention interact with WAL archiving
The rule that matters most is that no object a restore needs may expire before the restore is no longer possible. Backup tools write base backups and WAL segments as separate objects in the bucket, and point-in-time recovery needs a base backup plus every archived WAL file from that base backup's start up to the target time. If a retention rule removes the base backup but keeps the WAL, or removes WAL that falls between the oldest retained base backup and the newest one, the chain is broken and the recovery window shrinks without any error at backup time. Set retention so that the oldest recoverable point is defined by a complete base backup and its WAL, and expire whole chains together.
Three settings have to agree: the object lock retention period on the bucket or on each object, the retention policy in the backup tool, and the lifetime of WAL archive objects. Object lock in S3 blocks deletion or overwrite until the retain-until date passes, so any lock period shorter than the backup tool's retention window will not protect the data you intended to protect, and a lock period longer than the tool's window will leave objects the tool believes are gone, consuming storage and sometimes blocking its cleanup. Confirm with your storage provider how object lock, versioning and lifecycle expiration interact on your platform, since lifecycle rules can remove noncurrent versions that a lock was meant to keep.
Agreement on paper is not enough. Run a restore to a point in time near the oldest retained base backup, using only the immutable repository and the credentials a recovery operator would hold, and check that the restore reaches the target and that WAL replay completes without a missing segment. Repeat the test after any change to retention, lock mode or lifecycle rules. Record the result as evidence, because it shows the recovery window you can actually meet rather than the one the configuration suggests.
How to set up an immutable offsite repository
This sequence produces an off-site PostgreSQL backup copy that the database host cannot quietly delete or overwrite, plus a local repository for fast restores. Each step ends with a check so the team knows the control works before relying on it.
Create a separate backup account and administrators
Create a dedicated cloud account or project for backups, separate from the production account that runs the database. Assign its administrators from a group that does not overlap with production administrators, and enable multi-factor authentication for every human with access. Keep the backup account's billing and audit logs in a location the production team cannot change. Done when a production administrator cannot list, read or modify the backup account's resources, and that test is written down. Confirm the exact account-separation features your cloud provider offers before you design around them.
Create the bucket with versioning and object lock enabled
Create the object storage bucket in the backup account and turn on versioning and object lock at creation time, before any backup object is written. Choose a default retention mode and period that match your recovery policy, and confirm with your storage provider whether object lock can be enabled on an existing bucket. Block public access and disable any lifecycle rule that could expire backup objects early. Done when a test object uploaded to the bucket shows a version ID and the default retention is visible in the bucket settings.
Configure a writer credential that cannot delete or change retention
Create a machine identity for the PostgreSQL backup tool with a policy that allows writing and reading backup objects but denies deleting object versions, changing retention or lock settings, and changing bucket policies. Store its access keys in a secrets manager on the database side, not in the backup configuration file. Done when the identity can upload and list objects, and attempts to delete a locked object version or change its retention fail with an access error. Record the test results as evidence.
Set repository encryption with keys held outside the database host
Configure the backup tool's repository encryption using a passphrase or key that is stored outside the database host, for example in a separate secrets vault controlled by the security team. Keep a recovery copy of the key in a second controlled location, because an encrypted repository cannot be restored without it. Confirm that the backup tool's encryption settings are applied to the off-site repository and not only to the local one. Done when a restore test can run from a clean host that has only the bucket credentials and the key from the vault.
Configure the local repository for fast restores
Add a second repository on storage attached to the database network, using the same backup tool and its own retention settings. The local copy gives shorter restore times for common cases, while the off-site repository protects against loss of the host and its local storage. Set the backup configuration so each backup is written to both repositories, and confirm that a failure in one does not stop the other. Done when the backup tool reports a successful run for each repository and both show the same backup label.
Run the first backup to both repositories
Run a full backup and confirm the backup tool writes to the local and the off-site repository. Check the object storage console or listing for the new objects, confirm they have version IDs and lock retention, and check the backup tool's info output for both repositories. Record the backup label, the start and end times and the size reported for each copy. Done when both repositories list the same backup and the off-site objects show active retention.
Run a restore test from the off-site repository
Restore the first backup to a separate host that has no access to the production database, using only the off-site repository, the writer credential and the encryption key from the vault. Start the restored cluster, run row counts or checksums on a set of agreed tables, and confirm the database accepts connections. Record how long the restore took against the recovery time target your team has set. Done when the restored database matches the agreed checks and the test is written up as evidence. Repeat this test on a schedule, not only once.
Security and operational considerations
A backup repository is only as protected as the credentials that can write to it, change its retention and read its contents. The cards below cover the controls that keep those paths separate, watched and reviewed, so a compromised database host cannot quietly erase or expose the copies meant to recover it.
Separate the backup writer credential
The principal that writes backups should be distinct from the database role and from any application credential. Keep the database host's own access to the bucket to the minimum it needs, and do not let the database superuser or the server's instance profile hold delete or retention permissions. Check that a stolen database password cannot reach the repository, and that the writer identity cannot change its own bucket policy. Confirm this with a test using each credential against the bucket.
Grant the writer least privilege
The writer role usually needs to put objects, list the prefix it uses and read back what it wrote for verification. It should not hold permissions to delete versions, change object lock settings, alter lifecycle rules or edit bucket policy. Scope the policy to one bucket and one prefix per cluster. Ask your team to review the attached permissions each time the backup tool changes, because newer releases sometimes need an extra action.
Custody and rotation of encryption keys
Repository encryption is only useful if the key survives the incident it protects against. Store the repository encryption passphrase and any access keys in a secrets system that is not hosted on the database servers, and keep a sealed copy in a location with separate custody. Rotate access keys on a schedule and after staff changes, and rehearse a restore using only the documented key path. Losing the key makes every backup unreadable, so treat it as a recovery dependency.
Log and alert on bucket policy changes
Enable object-level and management event logging for the bucket and route events that change policy, lock configuration, versioning, lifecycle rules, replication or public access to an alert your security team watches. Changes to retention settings deserve the same priority as a failed backup job. Confirm which events your cloud provider records by default and which need explicit configuration, and test that an alert fires when a non-writer identity attempts a change.
Protect the retention configuration
Object lock retention and legal hold settings are only effective if the people and automation that could weaken them cannot do so quietly. Restrict who can shorten retention or remove a lock, require a second approver for those changes where your platform supports it, and record the approved retention period in the runbook. Confirm how the provider handles an attempt to reduce a locked retention period, because the answer determines whether the control protects you against an administrator acting in error.
Review backup access like production
Backup repositories contain full copies of production data, including personal data, credentials stored in tables and audit records. Put the bucket, its keys and its logs in the same access review cycle as the production database, with named owners, documented approvals and removal of leavers. Ask who can read objects, not only who can write them, and confirm that restore access is granted through a controlled process rather than standing permissions.
Questions teams ask before building offsite backups
What drives the cost and effort of offsite PostgreSQL backups?
The cost comes from three areas: the design work that sets retention, encryption, and account separation, the build of the backup tool and object storage configuration, and the ongoing storage, egress, and staff time that follows. Effort rises with the number of clusters, database size, daily change rate, how many restore paths you must prove, and how many people must approve key and credential custody. Storage charges depend on your provider's pricing for versioned or locked objects, so ask your cloud team to model retained versions before you commit. A quote should list each component separately, state what is one-time and what recurs, and name the environments in scope.
How long does it take to put immutable offsite backups in place?
Duration depends on how many clusters are in scope, whether object storage already exists in an account you control, how quickly approvals for keys and separate credentials come through, and how many restore tests the acceptance criteria require. A single cluster with an existing bucket is far simpler than a fleet across several accounts with legal hold rules. No fixed timeline applies to every environment, so the written scope should set milestones and name the dependencies on your side, such as network routes and account creation.
What must our team provide before the work starts?
Most delays come from missing inputs rather than from the build itself. Prepare these items before kickoff:
- An object storage account or bucket in a separate administrative domain from the primary database hosts, with a named owner
- A network path from backup hosts to the storage endpoint, including firewall rules and DNS
- A key custody decision: who holds the encryption passphrase or KMS key, where it is stored, and how it is recovered
- Named restore owners who can run a restore and sign off that the data is usable
- Retention periods agreed with the data owner and, where relevant, your compliance team
Without these, the immutable copy may exist but nobody can prove it restores.
Can our internal team build offsite PostgreSQL backups without a partner?
Yes, if the team already runs PostgreSQL in production and has someone comfortable with object storage policies, encryption keys, and restore procedures. The skills most often missing are not the backup command itself but the separation of duties: a backup credential that cannot delete objects, a retention lock that even administrators cannot shorten, and a tested runbook. Ask whether your team has time to run restore drills on a schedule and to document the evidence auditors will request. A partner is useful when the team needs an independent design review, a fixed-scope build, or a restore test performed by someone outside the original build.
How do we prove the immutable copy actually restores?
Confirm that a restore from the offsite repository, not the local one, produces a running cluster that passes data checks. Test a point-in-time recovery to a chosen timestamp, record the elapsed time, and compare row counts or checksums on critical tables. Use verification tools for the backup format, and keep the restore logs and results as evidence. Test with the credentials that a recovery would really use, because a restore that works only with an administrator account does not prove the copy is usable during an incident. Restore tests should also cover loss of the local repository and loss of the key.
What is the difference between object lock, versioning, and soft delete?
Versioning keeps prior object versions when something is overwritten or deleted, soft delete keeps deleted objects recoverable for a window, and object lock prevents deletion or overwrite for a fixed retention period or under a legal hold. Each control protects against a different failure. Confirm with your storage provider which of these it supports, how governance and compliance modes differ, and whether lock settings can be changed by an administrator. Also confirm how lifecycle rules interact with locked objects, because a lifecycle rule can otherwise expire copies earlier than your retention policy intends.
What recurs after go-live, and what should we schedule?
Recurring work includes storage charges that grow with retention, credential and key rotation, reviews of retention periods against data policy, restore drills at a set frequency, monitoring of backup job success and repository growth, and updates to the backup tool when security fixes are released. Plan a recurring restore test that uses the offsite copy and records timing against your recovery time target. Review retention whenever a database is added, a regulation changes, or a storage contract renews. Ongoing support and scheduled testing can be arranged as a retainer after the initial build.
Does DeployOpen issue a compliance certificate for our backups?
No. DeployOpen designs and builds the backup controls, prepares the restore evidence, and documents the configuration so your compliance team and independent auditors can assess it. Audit reports and certifications are issued by independent auditors and certification bodies, not by DeployOpen. Ask your auditor early which evidence they expect, such as configuration exports, lock settings, access reviews, and restore test records, so the build captures it from the start.
How DeployOpen works on this
DeployOpen scopes the backup repository design, configures it inside your own cloud accounts or storage, and proves restores from the off-site copy before handing over. Engagements are fixed-scope, with the object storage, credentials and restore tests agreed in writing first.
How we scope
- Confirm which object storage service, accounts and regions will hold the off-site repository, and who controls each account
- Map backup classes, retention periods and recovery point and recovery time targets to object lock modes and versioning rules
- Agree in writing the separation of duties between backup, storage and administrator credentials, and who approves changes
How we build
- Configure bucket versioning, object lock retention and soft delete on the off-site repository, then test that deletions and overwrites behave as documented
- Set up repository encryption with keys held separately from the database hosts, and document where key material is stored and who can rotate it
- Add a second, local repository for fast restores, and test that both repositories can be reached from the restore host without shared credentials
How we hand over
- Deliver a written runbook covering repository layout, retention settings, credential ownership and the steps to restore from either repository
- Provide the configuration as code, plus a record of the immutability and deletion tests run before handover
- Document restore timings from each repository so your team can compare them against the recovery targets you set
How we support
- Offer ongoing support and upgrades for the backup tooling as a retainer, with scheduled restore drills and reviews of retention and access settings
- Review changes to storage policies, account permissions and key rotation when your environment changes
- Ask your auditors which evidence they expect, such as retention settings, access logs and restore test records, and agree how we will prepare it

