Point-in-time recovery
| Also known as | PITR, continuous archiving, instant restore (Neon) |
|---|---|
| Built on | A base backup plus the archived write-ahead log |
| Offered by | Supabase (paid add-on), Amazon RDS, Neon; self-managed Postgres through configuration |
A table is dropped at 17:15 on a Tuesday and nobody notices until noon on Wednesday. With point-in-time recovery (PITR), the database can be rebuilt as it stood at 17:14 on Tuesday, with the table and every change made before it.1 The method restores an older full copy of the database files and then repeats, in order, every change recorded since that copy, stopping at the chosen moment. A daily Backup and restore can lose up to a day of writes; a point-in-time archive narrows that gap to minutes.2
Base backup and change log
Postgres writes every change to its data files into the write-ahead log (WAL) first. The log exists so that a server that crashes can return to a consistent state by repeating its most recent entries. It is stored as segment files of normally 16 MB, and without archiving the server recycles old segments once crash recovery no longer needs them.1 Continuous archiving copies each full segment to another place before it is recycled, so the log becomes an unbroken record of every change.
A restore needs two parts. The base backup is a file-level copy of the database directory; it may be internally inconsistent, because replaying the log repairs it in the same way crash recovery would. The archive must then hold every segment from the start of that base backup onward, without a gap. Replay can stop at any point after the end of the base backup, and the result is a consistent database as of that moment.1
A dump made with pg_dump cannot serve as the base. It holds SQL statements, not data files, and the log cannot be replayed on top of it. Recovery also restores the whole database cluster only, never a subset such as one table, and a busy server produces many megabytes of log that all need storage.1
Choosing the moment
The stopping point is the recovery target. In Postgres it can be a time stamp (recovery_target_time), a restore point named in advance with pg_create_restore_point(), a transaction ID, or a position in the log.3 Only the time and the named restore point are practical, because no tool helps to identify the right transaction ID.1 A time stamp takes a numeric offset from UTC or a full zone name such as Europe/Helsinki; zone abbreviations such as EEST are not accepted by default.3
The setting recovery_target_inclusive, on by default, keeps a transaction that committed exactly at the target. recovery_target_action defaults to pause: replay halts so that queries can confirm the dropped table is back, and pg_wal_replay_resume() then ends recovery. With hot_standby off, pause acts as shutdown.3
Each completed recovery opens a new timeline, a numbered branch of the database history. The timeline number is part of every log file name, so the log written after a restore never overwrites the log of the abandoned history. If the first moment chosen proves wrong, a later recovery can reach any point in the archive, including points on a branch left behind.1
Hosted databases
| Provider | Log upload and precision | What the restore replaces |
|---|---|---|
| Supabase, PITR add-on | Log uploaded every two minutes, sooner under heavy writes; target to the second | The project's own database |
| Amazon RDS | Transaction logs uploaded to S3 every five minutes; any time in the backup retention period | Nothing: the result is a new DB instance |
| Neon, instant restore | Any time in the history window, to the millisecond | The root branch, with its old state kept as a backup branch |
On Supabase, PITR is an add-on for Pro, Team and Enterprise projects. It takes a physical snapshot daily and uploads log files with the open-source tool WAL-G, which gives a worst-case recovery point objective of two minutes; while it is on, the daily backups stop. Seven days of history cost about $100 a month, 14 days about $200 and 28 days about $400. A restore starts from Start a restore in the Point in Time settings, overwrites the current database and makes the project unreachable for a time that grows with its size. Supabase advises restoring to a new project first.2
Amazon RDS reports the newest reachable moment in the LatestRestorableTime field, and the CLI command restore-db-instance-to-point-in-time builds the copy beside the source instance.4 Neon offers Time Travel Assist, which runs read-only queries against a past moment to find the right one, and names the preserved state {branch_name}_old_{head_timestamp}.5
What a restore leaves out
A database restore leaves files untouched. Supabase database backups hold only metadata about files kept in Storage, so a deleted upload stays deleted; Neon does not roll back its Object Storage either.25 A Neon restore also applies to every database on the branch, not only the one with the problem.5
The archive lives with the provider. Deleting a Supabase project removes all of its backups permanently, so a point-in-time history inside the project ends with the project.2 Copies kept elsewhere are covered under Ransomware and data destruction. On a self-managed server the log archive contains in effect the whole database, so the directory needs the same protection as the data, with no group or world read access.1 A copy left readable is an exposed backup.
GitLab.com, 2017
On 31 January 2017 an engineer rebuilding a lagging replica deleted the Postgres data directory on the primary server, believing it was the secondary. Replication had broken because the primary had already removed log segments the replica needed, and GitLab.com did not archive its log. The nightly pg_dump job had been failing on a version mismatch, and its S3 bucket was empty. GitLab restored a disk snapshot made by hand about six hours earlier and lost the database changes made between 17:20 and 23:30 UTC, an estimated 5,000 projects, 5,000 comments and 700 new user accounts. Evaluating WAL-E for database backup was among the follow-up items.6
Setting it up on a self-managed server
Archiving is switched on in postgresql.conf. The manual gives this command, labelled an example rather than a recommendation, which copies each segment to a directory and refuses to overwrite an existing file:1
wal_level = replica
archive_mode = on
archive_command = 'test ! -f "/mnt/server/archivedir/%f" && cp "%p" "/mnt/server/archivedir/%f"'Postgres deletes or reuses a segment once the command exits with zero, so the command must return zero only when the copy succeeded. Archiving has to work before the first base backup is taken. To recover, restore the base backup, set the restore command and the target, create an empty file named recovery.signal in the data directory and start the server:1
restore_command = 'cp "/mnt/server/archivedir/%f" "%p"'
recovery_target_time = '2026-11-17 17:14:00+00'Editing pg_hba.conf for the duration keeps ordinary users out until the restored data has been checked.1
In SecFlash
On the Cloud page, SecFlash reports SF-CLD-525 for a Supabase project with point-in-time recovery off and no finished backup from the last two days.
See also
- Backup and restore
- Ransomware and data destruction
- Exposed backups
- Security checklist before launch
- Responding to unauthorised changes to a website
- Category: Data exposure
References
- a b c d e f g h i j PostgreSQL Global Development Group. "25.3. Continuous Archiving and Point-in-Time Recovery (PITR)". PostgreSQL 19 documentation.
- a b c d Supabase. "Database Backups". Supabase documentation. Updated 12 November 2026.
- a b c PostgreSQL Global Development Group. "19.5. Write Ahead Log". PostgreSQL 19 documentation.
- back Amazon Web Services. "Restoring a DB instance to a specified time for Amazon RDS". Amazon RDS User Guide.
- a b c Neon (6 November 2026). "Instant restore". Neon documentation.
- back GitLab (10 February 2017). "Postmortem of database outage of January 31". GitLab blog.