Point-in-Time Recovery (PITR) in PostgreSQL
Point-in-Time Recovery (PITR) in PostgreSQL Point-in-Time Recovery (PITR) is a powerful feature in PostgreSQL that allows database administrators to restore a database to a specific moment in time—usually just before a failure, human error, or data corruption event. It’s an essential part of a solid disaster recovery plan . PITR relies on two key elements: Base Backup – A full copy of the database at a specific point. WAL (Write-Ahead Logging) – All changes after the base backup are written to WAL files , which are replayed during recovery. Advantages Undoing accidental DROP or DELETE operations. Recovering from logical corruption or bugs. Setting up test environments by cloning data at a specific time. Example 1. Enable WAL Archiving in postgresql.conf Edit the following parameters: wal_level = replica archive_mode = on archive_command = 'cp %p /var/lib/postgresql/wal_archive/%f' Restart PostgreSQL: sudo systemctl re...