---
title: "Plan for Disaster Recovery"
description: "Build a disaster recovery runbook for Managed PostgreSQL: which recovery path fits which failure, its data loss and time, and how to rehearse it."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/plan-disaster-recovery/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# Plan for Disaster Recovery

Turn the recovery capabilities of Managed PostgreSQL into a runbook: which path recovers which failure, what each path costs in data and time, the exact command sequence, and how to rehearse before you need any of it.

## Three Failures, Three Paths

Managed PostgreSQL gives you three distinct recovery paths, and they are not interchangeable:

| Failure | Recovery path | Relies on |
| --- | --- | --- |
| Bad data was written: a dropped table, a migration gone wrong, an `UPDATE` without a `WHERE` | Fork the service to a point in time just before the mistake | Base backups and WAL archiving, on every service; forking needs a `startup-*` plan or larger |
| The zone is unavailable | Promote a read replica running in another zone | A cross-zone replica you created **in advance** |
| The service was deleted | Restore your own dump into a new service | `pg_dump` files you keep outside the platform |

> [!WARNING]
> Failover inside a highly available plan (`business-*`, `premium-*`) is automatic, and only
> automatic. The API exposes no operation to promote a standby, to move the primary role, or to
> trigger a failover on demand, so you cannot fail over by hand and you cannot rehearse a failover.
> Rehearse disaster recovery with a **fork**, which is safe to create at any time and never touches
> the source service. See
> [High availability](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/high-availability/index.md).

Standby nodes also do not cover the zone scenario: all nodes of a service run in the same zone, so
an HA plan protects against node loss, not zone loss. Cross-zone redundancy comes from a read
replica in a second zone. See
[Limits and quotas](https://community.exoscale.com/product/dbaas/service-specific/postgresql/service-boundaries/limits-and-quotas/index.md).

## What Each Path Costs

No fixed recovery-time number is honest across plans and data sizes, so reason in mechanisms and
measure your own values in a drill:

- **Fork to a point in time.** Base backups are taken on a plan-defined cadence and every WAL
  segment is archived continuously, so you can land on any moment inside the recovery window: no
  earlier than the oldest retained base backup, no later than now. Data written after the target
  you choose is discarded by design, which in the bad-data scenario is the point. Time to recover
  is the fork creation, then your verification and the application switch: a small service comes
  up in a few minutes, a large one takes as long as its backup and WAL take to restore. See
  [Backups and point-in-time recovery](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/backups-and-pitr/index.md).
- **Promote a replica.** You lose whatever replication lag was outstanding when the zone went away.
  The lag is observable at any time with the queries below: measure it in steady state so you know
  the data loss this path would cost you today, instead of discovering it during an incident.
  Recovery time is one promote command plus the application switch.
- **Restore your own dump.** You lose everything written since the last dump you took: the cadence
  of your own `pg_dump` runs is the recovery point of this scenario, and the platform contributes
  nothing to it. Recovery time is creating a new service plus restoring the dump at full data
  volume.

Read the backup cadence and retention for the plan you run. On `startup-4`, for example, the
values are an interval of 24 hours, 3 base backups kept and recovery mode `pitr`:

```bash
exo dbaas type show pg --backup-config PLAN
```

Parameters:

- `PLAN`: the plan of your service, for example `startup-4`.

## Scenario 1: Bad Data Was Written

Fork the service to the last good moment. The source service keeps running, untouched, the whole
time, so nothing about this path can make the incident worse.

A service on a `hobbyist-*` plan cannot be forked. If this scenario matters for a service, run it
on a `startup-*` plan or larger, or keep your own dumps as in
[Scenario 3](#scenario-3-the-service-was-deleted).

1. If you can, stop the application component that wrote the bad data, so the incident has a clean
   end time.

2. Establish the recovery window:

   ```bash
   exo dbaas show my-postgresql -z ch-gva-2 --backups
   ```

   You cannot recover to a moment earlier than the oldest backup listed, and not later than now.

3. Choose the target timestamp: the minute *before* the incident began. A fork you throw away
   costs minutes, a fork that lands after the bad write costs the incident.

4. Create the fork:

   ```bash
   exo dbaas create pg PLAN FORK_NAME -z ch-gva-2 \
     --pg-fork-from my-postgresql \
     --pg-recovery-backup-time TIMESTAMP \
     --pg-ip-filter CIDR
   ```

   Parameters:

   - `PLAN`: plan of the fork, for example `startup-4`.
   - `FORK_NAME`: name of the new service, for example `my-postgresql-fork`.
   - `TIMESTAMP`: the ISO 8601 moment to recover to, in UTC, for example `2026-08-31T14:31:00Z`.
   - `CIDR`: a network block allowed to connect to the fork, for example `203.0.113.0/24`.

   To target the very start of the window, do not reuse a listed `backup-time` as is: it is
   truncated to whole seconds and the fork is rejected as out of range. Use a moment at least one
   second later.

5. Watch it come up, from `rebuilding` to `running`:

   ```bash
   exo dbaas show FORK_NAME -z ch-gva-2
   ```

6. Read the fork's connection URI, connect, and confirm it contains the state you aimed for. The
   fork has its own hostname, and the same roles and passwords as the source at the recovery
   point. Its IP filter is the one you passed at creation.

   ```bash
   exo dbaas show FORK_NAME -z ch-gva-2 --uri
   ```

7. Choose the way back, and make it an explicit step:

   - **Switch over entirely.** Repoint the application at the fork's URI, then treat the fork as
     the new production service: give it the integrations, IP filter and maintenance window the old
     one had. None of them is copied by the fork.
   - **Copy the damaged rows back.** Keep production on the source service, connect to the fork and
     copy the correct rows into production, for example with `pg_dump --data-only --table` from the
     fork and `psql` into the source, then delete the fork:

     ```bash
     exo dbaas update FORK_NAME -z ch-gva-2 -f --termination-protection=false
     exo dbaas delete FORK_NAME -z ch-gva-2 -f
     ```

## Scenario 2: The Zone Is Unavailable

This path only exists if you built it in advance. A replica created after the zone went down has
nothing to replicate from.

### Prepare, Before Any Incident

Create a read replica in a second zone, with the API as described in
[Use read replicas](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/use-read-replicas/index.md). A
replica needs a `startup-*` plan or larger.

```bash
exo api create-dbaas-service-pg REPLICA_NAME -z REPLICA_ZONE <<EOF
{
  "plan": "PLAN",
  "ip-filter": ["CIDR"],
  "integrations": [
    {
      "type": "read_replica",
      "source-service": "my-postgresql"
    }
  ]
}
EOF
```

Parameters:

- `REPLICA_NAME`: name of the replica service, for example `my-postgresql-replica`.
- `REPLICA_ZONE`: a zone different from the primary's, for example `at-vie-1`.
- `PLAN`: plan of the replica, for example `startup-4`.
- `CIDR`: a network block allowed to connect to the replica. Do not omit `ip-filter`: a replica
  created without one accepts no connections at all.

Then measure the lag in steady state, because it is the data this path loses. On the **primary**:

```sql
SELECT application_name, client_addr, state, sync_state,
       pg_wal_lsn_diff(sent_lsn, replay_lsn) AS replay_bytes
FROM pg_stat_replication
WHERE application_name <> 'pghoard';
```

The filter matters: the `pghoard` row is the platform's WAL archiver, not your replica. On the
**replica**:

```sql
SELECT pg_is_in_recovery() AS is_replica,
       pg_last_wal_receive_lsn(),
       pg_last_wal_replay_lsn(),
       now() - pg_last_xact_replay_timestamp() AS replica_lag;
```

How to read the two views together, including the idle-primary case, is covered on
[Use read replicas](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/use-read-replicas/index.md).

### Recover, When the Zone Goes Down

1. Confirm what you have. The list command searches every zone and needs no `-z`:

   ```bash
   exo dbaas read-replica list my-postgresql
   ```

2. On the replica, run the replica-side query above. With the primary unreachable, the last lag
   values you observed are your estimate of the data lost.

3. Promote:

   ```bash
   exo dbaas read-replica promote REPLICA_NAME -z REPLICA_ZONE -f
   ```

> [!CAUTION]
> Promotion is permanent and one-way. There is no command that re-attaches a promoted service to
> its former primary, and once promoted the two services diverge immediately: writes on the old
> primary never reach the promoted one, and vice versa. Make sure nothing can still write to the
> old primary's URI once you have promoted.

4. Repoint the application at the promoted service's URI:

   ```bash
   exo dbaas show REPLICA_NAME -z REPLICA_ZONE --uri
   ```

5. The promoted service is now an ordinary standalone primary. Review its IP filter, its backup
   expectations and its
   [maintenance window](https://community.exoscale.com/product/dbaas/how-to/maintenance-windows/index.md) before you consider the
   incident closed, and create a new replica for it in another zone: the one you just promoted no
   longer plays that role.

## Scenario 3: The Service Was Deleted

There is nothing to recover from the platform. A fork needs an existing source service: once the
service is deleted, `--pg-fork-from` answers `Service does not exist`. Platform backups cannot be
downloaded either. Plan as if deleting a service deletes your ability to recover it, and build
both protections in advance:

- **Keep termination protection on.** It is enabled by default on services created with
  `exo dbaas create`, and a protected service cannot be deleted until it is disabled. Verify it,
  especially on services created through the API or Terraform, in the `Termination Protected` row
  of:

  ```bash
  exo dbaas show my-postgresql -z ch-gva-2
  ```

- **Take your own logical dumps, on a schedule you choose.** Their cadence is the recovery point of
  this scenario:

  ```bash
  pg_dump --format=custom --file=BACKUP_FILE "SERVICE_URI"
  ```

  Parameters:

  - `BACKUP_FILE`: where to write the dump, for example `nightly-2026-08-31.dump`.
  - `SERVICE_URI`: the connection URI of the service, from
    `exo dbaas show my-postgresql -z ch-gva-2 --uri`.

  Store the files outside the platform, and keep them at least as long as your recovery
  obligations.

If the service is gone anyway, create a new service and restore the most recent dump into it:

```bash
pg_restore --no-owner --no-acl --dbname "TARGET_URI" BACKUP_FILE
```

Parameters:

- `TARGET_URI`: the connection URI of the database to restore into, on the new service.

For restore options and the errors these two flags avoid, see
[Migrate to Managed PostgreSQL](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/migrate-to-managed-postgresql/index.md).

## Rehearse Quarterly with a Fork Drill

A recovery procedure you have never run is a hypothesis, not a runbook. Because a fork never
touches its source, you can rehearse the whole path on production data with zero risk, so put a
drill on the calendar every quarter:

1. Fork production from its latest state:

   ```bash
   exo dbaas create pg PLAN FORK_NAME -z ch-gva-2 \
     --pg-fork-from my-postgresql \
     --pg-ip-filter CIDR
   ```

2. Time how long the fork takes to reach `running`, then read its URI, connect, and run the checks
   your application depends on: the tables you expect, the freshest rows you expect. That time,
   plus your verification, is your recovery time for the fork path. Write it down.

3. Rehearse the dump path in the same session, against the fork so production stays untouched:
   restore your latest `pg_dump` file into a scratch database on the fork and check it. Create the
   scratch database with `CREATE DATABASE drill_restore;`, restore with the `pg_restore` command
   above pointing at it, verify, then `DROP DATABASE drill_restore;`.

4. Delete the fork:

   ```bash
   exo dbaas update FORK_NAME -z ch-gva-2 -f --termination-protection=false
   exo dbaas delete FORK_NAME -z ch-gva-2 -f
   ```

> [!NOTE]
> The promote path cannot be rehearsed for free: promotion is one-way, so a promotion drill
> consumes the replica, and getting replication back means deleting the promoted service and
> creating a fresh replica that copies the data again from scratch. If you drill it, budget for the
> rebuild. The automatic failover inside multi-node plans cannot be rehearsed at all.

## Related Pages

- [Backups and point-in-time recovery](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/backups-and-pitr/index.md)
- [Fork a service and recover to a point in time](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/fork-a-service/index.md)
- [Use read replicas](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/use-read-replicas/index.md)
- [High availability](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/high-availability/index.md)
- [Limits and quotas](https://community.exoscale.com/product/dbaas/service-specific/postgresql/service-boundaries/limits-and-quotas/index.md)
- [Migrate to Managed PostgreSQL](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/migrate-to-managed-postgresql/index.md)

