Point-in-time recovery
(Updated )
Point-in-time recovery (PITR) allows you to restore your PlanetScale for Postgres database to any specific moment within your backup retention window. Unlike traditional backups that restore to specific backup snapshots, PITR gives you precise control over when to restore your data.
How PITR Works
PlanetScale for Postgres uses PostgreSQL's Write-Ahead Logging (WAL) system combined with periodic backups to enable PITR.
PostgreSQL's WAL system records all changes to the database before they're applied to the actual data files. Each transaction is first written to the WAL log, ensuring durability even if the system crashes. These WAL files are continuously archived, creating a complete record of every change made to your database. During PITR, PostgreSQL starts with a base backup and then "replays" the relevant WAL files to reconstruct the exact database state at your specified point in time.
In short, there are 3 key things to know about:
- Backups: Snapshots of your database taken at regular intervals
- WAL Archiving: Continuous archiving of all database changes as they occur
- Recovery Process: Restores from a base backup and replays WAL files to reach the exact point in time requested
Performing a point-in-time recovery
PITR is available for any point in time within your retention window — by default from 2 days ago up to 5 minutes before the current time (the 5-minute buffer ensures WAL files are fully processed and archived).
If you have created manual on-demand backups, have a custom backup schedule, or have enabled the Prevent backup deletion toggle on any backup, then PITR is available from the oldest backup available up to 5 minutes before the current time.
Note
Additional backups beyond the default incur additional charges. See Additional Backup Pricing for more information.
Create the PITR backup branch
- From the PlanetScale organization dashboard, select the desired database
- Navigate to the Backups page from the menu on the left
- On the right side of the page, you'll see a box labeled "Point-in-time recovery"
- Click the Branch dropdown to select the branch you'd like to restore from
- Select your target date and time within the available window
- Click Restore backup
- You'll see a summary of the selected branch, time you are restoring to, and size
- Name your new branch
- Select a cluster size
- Click "Restore backup"
This will create a new branch with the schema and data from the selected point in time. See Branching for next steps on how to connect and potentially promote your new branch.
Restore time considerations
When restoring to a point in time that is not close in time to one of your existing backups, the restore process can take significantly longer. PostgreSQL must start with the closest available backup and replay all WAL files from that backup until the target time.
For example: If you want to restore to a point 10 days ago, but your default backups only retain for 2 days, PostgreSQL will use your oldest available manual backup (say, 30 days old). It must then replay 20 days worth of WAL files to reach your target restoration point. This replay process can take hours or even days depending on the volume of database activity during that period.
When to Use PITR
Point-in-time recovery is ideal for:
- Data corruption recovery: Restore to just before corruption occurred
- Accidental deletions: Recover data that was mistakenly removed
- Failed migrations: Roll back to before a problematic schema change
- Compliance requirements: Access historical data states for auditing
Troubleshooting
"Recovery point not available"
- The requested time may be outside your retention window
- Check that the timestamp is at least 5 minutes ago
"WAL files missing"
- WAL archiving may have been interrupted
- Network connectivity issues during archival
- Storage system failures
- Consider using the nearest available backup point instead
If you need additional assistance, contact the PlanetScale support team.
Need help?
Get help from the PlanetScale Support team, or join our GitHub discussion board to see how others are using PlanetScale.