Home  Postgress   How pitr da ...

How PITR database recovery works for Postgress database

For Point-in-Time Recovery (PITR) to work, the PostgreSQL system needs to be backing up continuously.

Here is how that works and why the two components—Base Backups and WALs—are both essential for continuous recovery:


The PITR Continuous Loop 🔄

Point-in-Time Recovery relies on two separate, but connected, processes to capture the database's state continuously:

1. Base Backup (The Starting Point) 💾

The physical backup (or "base backup") is the full snapshot of the database files taken at a specific moment. This is the foundation of your recovery.

<hr>

2. Continuous WAL Archiving (The Continuous Changes) 📝

The Write-Ahead Log (WAL) is a journal of every single change (insert, update, delete) made to the database. These small log files are generated constantly. For PITR, the system is configured to archive these small files as soon as they are filled up.

<hr>

How the Recovery Works

To perform a PITR, you tell PostgreSQL the exact date and time you want to go back to (e.g., Tuesday at 1:17 PM).

  1. Restore the Base Backup: PostgreSQL first restores the last complete physical base backup (e.g., the one from Monday at 8:00 AM).
  2. Apply the WALs: It then starts loading and applying the archived WAL files in order, replaying every transaction.
  3. Stop at the Point-in-Time: When the system reaches the requested time (1:17 PM), it stops applying the changes.

Since the WAL files contain the record of changes up to the very last second, you can effectively rewind the database to any arbitrary second between your base backups.

Published on: Sep 30, 2025, 09:05 AM  
 

Comments

Add your comment