# Point-in-time restore for databases

> Put a MariaDB or PostgreSQL database back to any moment within the retention period, for example just before a failed update, next to the live database or over it, using the binary log or the WAL archive.

Source: https://www.berthpanel.app/library/point-in-time-restore/ · Category: data · Updated: 2026-10-29

A nightly backup gets you back to last night. When a plug-in update corrupts a shop's orders at 14:32, you want the database as it was at 14:31, not twelve hours of orders lost. Point-in-time restore does that: Berth keeps a log of every change and replays it on top of the last backup up to the moment you choose, for one database, without touching the others.

It is available for MariaDB (through the binary log) and PostgreSQL (through the WAL archive). The administrator switches it on for the server; customers then use it for their own databases.

## How it works

### MariaDB

MariaDB writes every change to its binary log. Berth keeps that log for the retention period, and every database dump in a backup archive records its exact position in the log. To restore a database to a moment, the panel:

1. takes the last backup archive from before that moment;
2. restores that dump;
3. replays the binary log after it up to the chosen moment, for that database only.

This works from the first backup made after point-in-time restore was switched on.

### PostgreSQL

PostgreSQL archives every WAL segment (its write-ahead log) in compressed form to a directory managed by Berth, and the backup round makes a **base backup** every night with `pg_basebackup`. Restoring one database works like this:

1. the base backup from before the moment is unpacked into a temporary PostgreSQL instance, which only listens on a private socket and does no archiving;
2. the WAL is replayed in that instance up to the moment;
3. that one database is dumped from the temporary instance and restored into the real server, next to the live one or over it.

The other databases on the server notice nothing. Restoring is possible from the end of the oldest base backup.

## Switching it on (administrator)

On *Databases*, open *Server settings*.

- **MariaDB**: the card *Point-in-time restore*. Set the **Retention** in days: 7 by default, at most 35, 0 switches it off. Saving restarts MariaDB.
- **PostgreSQL**: the card *PostgreSQL · Point-in-time restore*. It is switched on automatically, with 7 days, when PostgreSQL is set up for the first PostgreSQL database. On a server where PostgreSQL was already running you switch it on yourself; that restarts PostgreSQL. If PostgreSQL already archives with its own `archive_command`, Berth leaves it alone and says so.

```bash
berth database pitr                      # show the state
berth database pitr --days 7             # MariaDB: keep 7 days (restarts MariaDB)
berth database pitr --postgresql --days 7
berth database pitr --postgresql --base  # make a PostgreSQL base backup now
berth database pitr --days 0             # switch off for MariaDB
```

The PostgreSQL card shows, per day, whether it can be restored, the earliest moment you can go back to, the last archived segment and how many are waiting, the base backups and the free disk space. **Base backup now** makes one immediately.

### Disk space

The logs cost disk space: roughly all changes of the retention period. On most servers that is somewhere between a few hundred megabytes and a few gigabytes, more for busy shops. Switching retention to 0 for PostgreSQL also removes the kept WAL and base backups.

### Alerts

The administrators are alerted when WAL archiving fails, when it falls behind, and when the newest PostgreSQL base backup is too old. See [Notifications and alerts](https://www.berthpanel.app/library/notifications-and-alerts/).

## Restoring a database to a moment

1. On *Databases*, open the database's row and choose **Restore to a point in time…**.
2. Enter the **Moment** in the server's time zone, for example just before a failed update. The dialog says how far back you can go.
3. Under **Where does it go?**, choose:
   - **Next to what is there now**: the result becomes a new database and the current one stays as it is. Nothing is lost; you can compare first. This is the default.
   - **Instead of what is there now**: the database gets the content of that moment, and everything that changed afterwards is lost.
4. Click **Restore**. The result lists the steps taken and, for a restore next to the original, the name of the new database.

```bash
berth database restore-at --database acme_shop --at "2026-10-28 14:31" --alongside
berth database restore-at --database acme_shop --at "2026-10-28T14:31:00+01:00"
```

The moment can be given as `yyyy-mm-dd hh:mm[:ss]` in server time, or in RFC 3339 with a time zone. Without `--alongside`, the database is replaced. The same is available in the API as `POST /api/v1/databases/{name}/restore-at`.

> [!TIP]
> Restore next to the live database first, check the copy (for example in Adminer), and only then decide whether to swap it in or to copy back just the rows you need.

## Restoring the whole PostgreSQL cluster

Sometimes one database is not enough, for example after a mistake that touched roles as well. The administrator can put the whole PostgreSQL cluster back to a moment: *Restore the whole cluster…* on the PostgreSQL card, which you confirm by typing `postgresql`.

```bash
berth database restore-cluster --at "2026-10-28 14:31" --confirm postgresql
```

- All databases and roles, including passwords, go back to that moment. Databases that did not exist yet at that time disappear; the result names them.
- PostgreSQL is stopped briefly. The current data directory is kept for a day next to the restored one, so you can still go back.
- If replaying fails, Berth puts everything back as it was.
- A fresh base backup follows immediately.

## Point-in-time restore and backups

Point-in-time restore is a fine-grained undo on the server itself, built on top of the regular backups. It does not replace off-site backups: keep a copy of your backups on S3 or a NAS as well, see [Backups overview](https://www.berthpanel.app/library/backups-overview/). To restore a database from a specific archive or from the hourly history instead, see [Restoring data](https://www.berthpanel.app/library/restoring-data/).
