---
title: "Restore a PostgreSQL database in 2026: point in time or pg_dump"
url: https://while.sh/en/guides/restore-postgresql/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-19
---

# Restore your PostgreSQL database to a precise moment, or from a pg_dump (2026)

A failed migration, a table emptied by mistake: your database goes back to the moment before, with a simple request to your AI. A safety backup is taken first, and in production, nothing happens without your approval.

> **The short version.** Made a mistake in your data? Your AI restores your PostgreSQL database to yesterday at 6 pm, or imports a pg_dump. A safety backup comes first. What matters, like deleting a database, waits for a person's approval.

## Prerequisites

- An app deployed on while, with its PostgreSQL database.
- Your AI, connected to while over MCP.

## Step 1: Tell your AI where to go back to

> You, to your AI: Restore the database to yesterday at 6 pm.

Your AI prepares the restore, to the moment you asked for, and gives you a link.

## Step 2: Approve

You open the link and approve, or an administrator does, depending on your permissions. A safety backup is taken first, then the restored database takes the place of the old one.

## What your AI does

Your database archives its write-ahead log continuously and takes a full backup every day, with nothing for you to declare: that's what lets it go back to a precise moment (source 1). Your AI picks the point to go back to, a backup or a moment, within the 14 days they are kept. The restored database is created separately, then takes the place of the old one: nothing is overwritten before you approve.


<figure class="illus"><img src="/illustrations/guide-fonction-garde-1200.webp" srcset="/illustrations/guide-fonction-garde-768.webp 768w, /illustrations/guide-fonction-garde-1200.webp 1200w" sizes="(min-width: 48rem) 46rem, 100vw" width="1536" height="1024" loading="lazy" decoding="async" alt="Restoring a PostgreSQL database with while: credentials kept out of the AI's reach, every call logged in the history, a person's approval for what matters and a daily backup, in France" /><figcaption>Around every app, while keeps the credentials, the history, the approvals and the backups.</figcaption></figure>

## Check that a backup really works

> You, to your AI: Take a backup and check it.

Your AI starts a backup, followed right away by a test: a throwaway database is created from it, and its tables are read back.

## Import a pg_dump export

> You, to your AI: Import our Heroku export into the database.

Your AI uploads the export, then loads it into your database with `pg_restore`, separately from your app (source 2).

## Find the rows involved before you go back

> You, to your AI: Show me the orders deleted since yesterday.

Your AI reads your database in SQL over MCP, with your permissions on the data and without being able to write to it, and shows you the rows involved before you choose the moment.

## Go back to the previous version

> You, to your AI: Go back to the previous version.

In the 30 minutes after a production release, the previous version comes back in a second. After that, it takes a few seconds. Once the previous version is back, your AI reads what broke in while's logs, fixes it and deploys again.

## Next steps

- [Deploy a Node.js API and its PostgreSQL database](/en/guides/deploy-node-api-postgresql/)
- [Go back to the previous version in a second](/en/guides/rollback/)
- [Compare PostgreSQL hosting](/en/comparisons/managed-postgresql-hosting/)

## Sources

1. [PostgreSQL, continuous archiving and point-in-time recovery](https://www.postgresql.org/docs/current/continuous-archiving.html), 2026-11-02
2. [PostgreSQL, the pg_restore command](https://www.postgresql.org/docs/current/app-pgrestore.html), 2026-11-02

## Questions

### How far back can I go?

Up to 14 days, to a backup or to a precise moment.

### Can my AI restore production without me?

No. In production, the restore waits for your approval, or an administrator's, depending on your permissions.

### Are the backups really tested?

Yes. Every day, a throwaway database is created from the latest production backup, and its tables are read back. The result is shown.

### Where are the backups kept?

In France, encrypted, outside your database's cluster, for 14 days.

### Does restoring the database change my code?

No. The database and the code go back separately: your AI also brings back the previous version of the app, if needed.
