PostgreSQL Backups and Restore¶
The platform backs up your PostgreSQL instances. Each instance with backups on gets:
- Scheduled backups: a full copy of the database at the interval and hour you choose.
- Continuous archiving: every change is archived as it is written, so you can restore the database as it was at any moment between its backups, up to now.
- A retention period: you choose how many days backups and archived changes are kept. They are kept as long as needed to restore to any point in that period, then deleted automatically.
You restore by creating a new instance from another instance's backups: from a backup, from a point in time, or from the latest state. An instance is never overwritten in place.
Backups are stored in a backup store on the same Kubernetes cluster as the instance, on their own volumes. Each instance gets its own storage area, with its own credentials and its own size limit.
What backups protect against
Backups protect your data from mistakes, failed changes and the loss of an instance's disks. Because the store is on the same cluster, they don't protect it from losing that whole cluster or its storage system. If you need that, also keep copies outside the platform, for example with pg_dump.
When backups are available¶
- New instances get backups on by default, daily, when their cluster can take them. Where it can't, they are created with backups off; the create isn't refused for that.
- Instances created before backups existed keep them off until you turn them on.
Whether an instance's cluster can take backups depends on how your organization administrator set up PostgreSQL there (see Backup store). When it can't, the instance shows backups as unavailable and why, and turning them on or backing up now is refused with that reason. Backups taken earlier stay listed and can be deleted; they can be restored again once the cluster can take backups.
The backup policy¶
An instance's backup policy has four settings:
| Setting | Values | Default for a new instance |
|---|---|---|
| Backups | On or off | On |
| Interval | Every 1 to 7 days | Every day |
| Hour | 0 to 23, in UTC | An hour between 00 and 05 UTC, picked from the instance's ID |
| Retention | 1 to 30 days, unless your platform operator set another maximum | 7 days, unless your platform operator set another default |
You can set them when you create the instance, or change them later.
New instances get different default hours, and the minute within the hour is spread the same way, so instances that share a backup store don't all start at once. An instance that turns backups on for the first time without choosing an hour gets one the same way.
Changing the policy is a change like a resize: it works while the instance is Active or Degraded, one change at a time, and the instance shows Updating while it runs.
Schedule¶
All times are UTC. Backups start in the hour you chose:
| Interval | Runs |
|---|---|
| 1 day | Every day |
| 7 days | Every Sunday |
| 2 to 6 days | On days 1, 1+N, 1+2N… of each month |
With 2 to 6 days, the sequence starts again on the 1st of every month, so the last gap of a month is shorter than the interval, never longer. Every 3 days, for example, runs on the 28th, the 31st and then the 1st.
Retention¶
Retention is how many days backups and archived changes are kept: a time window, not a number of backups, and independent of the interval. Changing the interval keeps the retention.
- You can choose from 1 day up to a maximum, 30 days unless your platform operator set another. The instance shows the range.
- An instance where you never chose one follows the default, 7 days unless your platform operator set another, and shows that its retention is the default. Once you choose a value, even the same number as the default, the instance keeps it. To follow the default again, choose the default itself rather than its number.
- If your platform operator changes the default, instances that follow it show the new retention right away, but it takes effect on the instance's next policy change, resize, upgrade or Sync.
- If you need backups kept longer than the maximum, ask your platform operator: they can set a longer retention for one instance.
Every backup inside the window is kept, scheduled and manual alike: back up now, the first backup after backups are turned on, and the backup a major upgrade takes first. The newest backup that ended before the window is kept too, so you can restore to any point in the window. Older backups and archived changes are deleted automatically. A month with one extra backup (see Schedule) only keeps it until it leaves the window.
All kept backups count toward the instance's backup storage limit, so a longer retention needs more backup storage.
If the instance's retention is outside the range, because your platform operator set it or lowered the maximum since, every change to the backup policy is refused unless it also sets a retention within the range or goes back to the default. That ends a longer retention your platform operator set, so to keep it, ask them to make the change. Turning backups off works, unless the same change sets a retention outside the range.
Turn backups on or off¶
Turning backups on or off restarts the database
The instance's pods restart to add or remove the component that archives changes. The primary restarts in place, without switching over to a standby, so the database is briefly unavailable and connections drop, even with high availability. Changing only the interval, hour or retention doesn't restart anything.
Turning backups on takes a first backup straight away, named enabled-<date and time> and listed as manual. Backup health shows pending until archiving has started, and the recovery window starts once that first backup completes.
Turning backups off stops scheduled backups and archiving. The backups already taken stay listed, and you can still restore from them and delete them. While backups are off, nothing deletes them automatically and they still count toward the instance's backup storage. The recovery window then ends at the newest backup, so you can restore only from a backup, not from a point in time or the latest state.
Turning backups on again takes a new first backup. The recovery window restarts from it; earlier backups can still be restored as backups.
Backups¶
The instance's backups are listed newest first, read live from its cluster. Each one shows its name, its type (scheduled or manual), its state (pending, running, completed or failed), the PostgreSQL major version it was taken on, when it started and ended, and why it failed if it did. After a major version upgrade, backups of the earlier version stay listed and are marked as restorable from the backup only. The list also shows the PostgreSQL major version the instance runs now.
| Name | Taken by |
|---|---|
scheduled-<date and time> |
The schedule |
manual-<ID> |
Back up now |
enabled-<date and time> |
Turning backups on, or the first backup after a major upgrade (listed as manual) |
pre-upgrade-<earlier major>-<date and time> |
A major version upgrade with backups on, on the earlier version before it upgrades (listed as manual) |
Back up now¶
Back up now takes a full backup straight away, in addition to the schedule. Backups must be on, and the instance Active or Degraded.
- The instance keeps its status while the backup runs. A change that restarts the database meanwhile, such as a resize, can make the backup fail. The backup is recorded in the instance's Action History.
- One backup operation (back up now or a delete) runs on an instance at a time, and it can't be cancelled.
- The instance can't be deleted while a backup operation runs.
- Manual backups are kept for the same retention as scheduled ones, and count toward the backup storage limit.
Delete a backup¶
Deleting a backup removes its own data from the backup storage. Archived changes are removed only when you delete the oldest backup, and then only those from before the oldest backup left. Deleting any other backup frees only that backup's data.
- A backup that is still pending or running can't be deleted.
- Deleting the last completed backup of the PostgreSQL version the instance runs now needs an extra confirmation: point-in-time and latest restores start from such a backup. Backups of an earlier version don't count. Deleting the instance's only completed backup needs the confirmation too.
- Deleting the backup the recovery window starts from moves its start later.
- Backups can't be deleted while an instance is being restored from them.
- You can delete backups while backups are off.
Recovery window¶
The recovery window is the span of time you can restore the instance to:
- It starts at the end of the first backup completed since backups were last turned on or the instance last moved to a new major version (with backups off, at the end of the oldest backup left of the version it runs now).
- It ends now while archiving is continuous: backups are on, archiving works and the backup storage isn't full. Otherwise it ends at the end of the newest completed backup.
- It covers only the PostgreSQL major version the instance runs now. Backups of an earlier version can be restored only as backups.
- It is empty until a backup completes after backups are turned on, or after a major version upgrade.
Retention moves the start forward as old backups are deleted.
While the window is continuous, you can restore to any moment inside it, including the latest state. While it isn't, you can restore only from a backup.
Backup health¶
Backup health shows whether archiving works, since when, and a message when it doesn't:
| State | Meaning |
|---|---|
| Healthy | Archiving works. |
| Pending | Backups were just turned on: health is known once archiving has started or the first backup has completed, usually within a few minutes. |
| Failing | Archiving fails; the message says why. The recovery window isn't continuous. |
| Storage full | The instance's backup storage reached its limit. See below. |
| Disabled | Backups are off. |
Backup storage and its limit¶
The instance shows how much backup storage it uses and its limit. Usage is measured periodically, not live.
The limit is three times the instance's Storage (GiB) by default, and it grows when you grow the instance's storage. If your platform operator changes the factor, the change applies on the instance's next policy change, resize, upgrade or Sync.
You can't change the limit yourself: if you need another one, for example for a longer retention, ask your platform operator, who can set one for the instance. A limit they set stays when you resize the instance, until they change it or put it back to the default. A limit below what the backups already use makes the backup storage full right away.
The limit isn't reserved space: the backup store is shared with the other instances on the same cluster. If the store itself fills up, archiving fails (backup health shows Failing) even below the limit; ask your organization administrator to grow it.
When the backup storage is full:
- The store refuses new writes to it, within about a minute of reaching the limit, so usage can briefly go over it. Archiving stops and new backups fail. Backup health shows Storage full.
- The recovery window stops being continuous, so you can restore only from existing backups.
- PostgreSQL keeps the changes it couldn't archive on the instance's own disk. If that disk fills up too, the database stops. Act promptly.
- A major version upgrade fails before it upgrades anything, because it can't take its first backup. See If the backup before the upgrade fails.
Writes stay refused until usage is back under the limit; archiving then resumes by itself. To get there, delete backups, most of all the oldest one (see Delete a backup); wait for old backups to leave the retention window, or shorten the retention so they leave it sooner; grow the instance's storage, which raises a default limit; or ask your platform operator for a larger limit.
Restore into a new instance¶
A restore creates a new instance from the backups of another instance, the source. The source keeps running, and its data is only read. Choose one restore point:
| Restore point | You get | Needs |
|---|---|---|
| A backup | The database as it was at the end of that backup, when the source can archive its newest changes first. For a backup of an earlier version, or when the source can't (for example with backups off), the database as of the backup's consistent point, possibly a few seconds before the backup started | A completed backup of the source, of any PostgreSQL version it has run |
| A point in time | The database as it was at that moment | A time inside the source's recovery window, not in the future, while the window is continuous |
| The latest state | Everything the source committed before the restore started | A continuous recovery window |
You start a restore from the source instance: from its operations, from one of its completed backups, or from its recovery window. Then pick the restore point and fill in the rest as for a new instance; the project and service config are the source's.
Rules¶
- The new instance must be in the same project and on the same service config as the source.
- Its PostgreSQL major version is the one the backup was taken on when you restore from a backup, even an earlier version than the source runs now. For a point in time or the latest state, it is the source's current major version. The source's current major version is the one its backups list shows: after a failed major upgrade the source shows the version you asked for but still runs the earlier one, and restores use that one.
- Its storage must be at least the source's.
- It keeps the source's database and owner names.
- Its tier, high availability, monitoring and its own backup policy are chosen as for any instance. Its backups go to its own storage, with its own limit (three times its own storage by default), never the source's.
- The source must be running: not being created or deleted, and not in Error. For a point in time or the latest state, it must also be Active or Degraded: while a change runs on the source, restore from a backup or wait until the change is done.
- The source's cluster must be able to take backups.
- It uses one
postgresql-instancesquota unit, like any instance.
These are checked before anything is created; a refused restore creates nothing and uses no quota.
What happens during a restore¶
The new instance goes through Pending and Creating to Active. Its create action is named Restore PostgreSQL Instance and says what it restores. A restore takes a few minutes, more for a large database or many changes to replay since the backup, and fails if it takes longer than about 40 minutes (the default).
- When the source has backups on and a ready primary, it first commits one tiny transaction and archives its newest changes, whatever the restore point, so the restore can reach them. Even a backup that has just completed can then be restored straight away.
- For a point in time or the latest state, the restore starts from the newest backup of the source's current version that ended before that point. The platform picks it; there is nothing to choose.
- The restored instance shows the instance it was restored from. It has its own address and password: load its connection details.
- With backups on, it takes its own first backup once it is up.
While an instance is being restored from it, the source can't be deleted and its backups can't be deleted; back up now still works. If a restore is interrupted, which is rare, the new instance can stay Creating for up to two hours before it fails, and the source's deletes stay refused until then.
If a restore fails¶
The new instance goes to Error and can only be deleted. Delete it, which also removes its access to the source's backups, and start a new restore.
- Choose restore points well inside the recovery window: retention can delete the backup, or the start of the window, between the check and the restore.
- For a point in time close to now, leave a few seconds of margin, or restore the latest state instead.
Major version upgrades¶
Instances with backups can move to a newer PostgreSQL major version, for example from 16 to 17, like any other instance (see Upgrade the PostgreSQL version). With backups on, the upgrade:
- Takes a backup on the current version, with the instance up.
- Only then upgrades the database. The instance is down for about 3 minutes, or about 5 with high availability.
- Takes a first backup on the new version. The recovery window starts again from it.
The instance keeps one backup storage for all its versions:
- Backups of every version stay listed, each with its version, and expire with the normal retention. Until then they count toward the instance's backup storage.
- A backup of an earlier version can be restored only from that backup, by its name, into a new instance of that version.
- Point-in-time and latest restores work only within the version the instance runs now, from the end of the first backup after the upgrade.
Minor upgrades don't affect backups.
If the backup before the upgrade fails¶
If the backup on the current version fails, for example because the instance's backup storage is full, nothing is upgraded:
- The instance keeps running the earlier version.
- The upgrade shows as failed in the instance's Action History, and the instance shows Degraded and the version you asked for. The backups list shows the version it really runs, and restores follow that one.
To recover, fix the cause, then run Sync, which retries the upgrade. Requesting the upgrade again does nothing, because the instance already shows that version. When the backup storage is full, free some or raise the limit first:
- delete old backups, most of all the oldest one (see Delete a backup);
- wait for old backups to leave the retention window;
- grow the instance's storage, which raises a default limit;
- ask your platform operator for a larger limit.
A raised limit can take about a minute to apply, so if the first retry fails again, run Sync again after a minute.
Any change you make meanwhile, such as a resize or a backup policy change, also retries the upgrade first. If the upgrade succeeds, the instance is down for those few minutes; if it fails again, the change fails with it.
You can't go back to the earlier version: upgrades only move forward.
Limitations¶
- Turning backups on or off restarts the database (see above).
- Restores always create a new instance, in the same project and service config. Backups of an earlier PostgreSQL version restore only from the backup itself, into that version.
- Backups can't be downloaded. Use
pg_dumpfor a copy outside the platform.
Deleting an instance deletes its backups¶
Deleting an instance permanently deletes all its backups and their data. To keep the data, restore it into another instance first, or take a dump.
The delete is refused while a backup operation runs on the instance, and while another instance is being restored from it.
Permissions¶
| Task | Permission |
|---|---|
| See the backup policy, backups, recovery window, health and storage | postgresql_instance_backup_get |
| Change the backup policy | postgresql_instance_backup_policy_update |
| Back up now | postgresql_instance_backup_create |
| Delete a backup | postgresql_instance_backup_delete |
| Restore | postgresql_instance_create in the project, plus postgresql_instance_backup_get on the source |
postgresql_instance_get includes postgresql_instance_backup_get, and postgresql_instance_update includes the three changes. Full list: Permissions Reference.