Point-in-Time Recovery (PITR) Database Setup
Imagine: at 14:37 someone accidentally drops the orders table, or at 09:15 a mass incorrect UPDATE hits a million rows. Without PITR, recovery is only to the last backup — all data after that is lost. We solve this by configuring Point-in-Time Recovery for PostgreSQL and MySQL, so you can roll back to any second. Standard backups protect against full failure, but not logical errors. PITR enables recovery with transaction-level precision. Key metrics: RPO (Recovery Point Objective) — maximum data loss. With archive_timeout=300, RPO ≤ 5 minutes. RTO (Recovery Time Objective) — recovery time. For a 100 GB database, 15–40 minutes. Without PITR, recovery can take days instead of hours, and lost data is often unrecoverable. According to PostgreSQL documentation, WAL archiving is the foundation of PITR. Savings from a single data deletion incident can exceed $5,000.
Why PITR Is a Necessity, Not an Option
Without PITR, you lose all changes after the last backup. This can cost hours of work and reputation damage. With PITR, you recover to the moment just before the error, losing only a few minutes. Time savings during rollback are 10x faster than re-entering data.
Supported Databases
- PostgreSQL — pgBackRest with replication to S3.
- MySQL — binary logs with
binlog_format=ROW.
How PITR Works
It requires two components: a base snapshot (full backup) and a continuous stream of transaction logs from the snapshot to the current time (WAL for PostgreSQL, binlog for MySQL). Recovery = base snapshot + replay of logs up to the desired point. Storage cost for WAL archives in S3 for a 100 GB database is about $15/month. Each WAL segment is 16 MB and has a unique Log Sequence Number (LSN), allowing precisely targeted recovery.
PITR Setup for PostgreSQL
WAL Archiving Configuration
In postgresql.conf:
wal_level = replica archive_mode = on archive_command = 'pgbackrest --stanza=myapp archive-push %p' archive_timeout = 300 A PostgreSQL restart is required after changing wal_level.
pgBackRest: Complete PITR Configuration
# /etc/pgbackrest/pgbackrest.conf [global] repo1-path=/mnt/backup-storage/pgbackrest repo1-retention-full=3 repo1-retention-archive=14 repo2-type=s3 repo2-path=/pgbackrest repo2-s3-bucket=company-db-backups repo2-s3-region=eu-west-1 repo2-retention-full=2 [myapp] pg1-path=/var/lib/postgresql/14/main pg1-port=5432 Point-in-Time Restore
systemctl stop postgresql pgbackrest --stanza=myapp restore \ --target="YYYY-MM-DD HH:MM:SS" \ --target-action=promote \ --delta systemctl start postgresql Replace --target with the desired timestamp. --delta restores only changed files, speeding up the process.
PITR Setup for MySQL via binlog
Binary Log Configuration
# /etc/mysql/mysql.conf.d/mysqld.cnf server_id = 1 log_bin = /var/log/mysql/mysql-bin.log binlog_format = ROW expire_logs_days = 14 max_binlog_size = 500M binlog_row_image = FULL Recovery Using mysqlbinlog
mysql -u root myapp < full_backup_YYYYMMDD.sql mysqlbinlog \ --stop-datetime="YYYY-MM-DD HH:MM:SS" \ /var/log/mysql/mysql-bin.000040 \ /var/log/mysql/mysql-bin.000041 \ /var/log/mysql/mysql-bin.000042 | mysql -u root myapp To skip a problematic transaction, specify --start-position and --stop-position in mysqlbinlog to exclude the corrupt event.
Choosing Between PITR on PostgreSQL and MySQL
| Parameter | PostgreSQL (pgBackRest) | MySQL (binlog) |
|---|---|---|
| Default RPO | 5 minutes | ≤ 1 minute (no delay) |
| RTO for 100 GB | 15–40 minutes | 10–30 minutes |
| Built-in replication | Streaming (native) | Async/semi-sync (native) |
| Archive storage | S3, local, NFS | Filesystem, S3 (via tools) |
| LSN-based recovery | Yes | No (time/position only) |
PostgreSQL offers more flexibility (LSN recovery, parallel apply) but requires more careful tuning. MySQL is simpler to configure, but binlog files can consume significant space with ROW format.
Local vs S3 Storage for WAL Archive
| Parameter | Local Disk | S3 (Cloud) |
|---|---|---|
| Write speed | High (NVMe) | Moderate (depends on bandwidth) |
| Reliability | Limited (disk failure) | High (7×9 replication) |
| Cost | One-time | Monthly (~$15/month for 100 GB) |
| Internet recovery | Local only | Anywhere |
| Recommendation | For databases < 50 GB | For databases > 50 GB and DR |
Our PITR Setup Process
- Audit current infrastructure — determine database size, change frequency, RTO/RPO requirements.
- Configure archiving — set up WAL/binlog, choose repository (local disk + S3).
- Test restore — verify recovery to a random point in an isolated environment.
- Documentation — record procedures, create a runbook for on-call engineers.
- Training — conduct a workshop for your team on manual and automated recovery.
Common Mistakes and How to Avoid Them
- Missing WAL segment due to incorrect
archive_command— ensure the command exits with code 0. Usepgbackrest --stanza=myapp check. - Too large
archive_timeoutinterval — increases RPO. Keep it at 5 minutes or less. - No archive replication — we use S3 in another region for disaster recovery.
- Lack of regular drills — recovery without testing can fail at a critical moment.
Schedule a test restore at least once a quarter. We help with this.
What's Included
- Full PITR setup for PostgreSQL and/or MySQL.
- Configuration of pgBackRest or binlog with cloud backup.
- Test restore and results report.
- Recovery procedure documentation (runbook).
- Training for your engineers.
- Recovery guarantee to any point in time within the configured period.
Timeline and Cost
Setup time: 2 to 5 business days depending on infrastructure complexity (replication, S3, clustering). Cost starts from $2,500 for a single database setup. Order PITR setup now — protect your data. For a consultation, contact us: your personal manager will assess the system in one day.
We have over 10 years of experience in PostgreSQL and MySQL administration, completed more than 40 PITR projects. Our engineers are certified and regularly undergo training. We guarantee data recovery within agreed RTO/RPO. Contact us for a consultation.
For further reading: official PostgreSQL documentation on WAL and MySQL Binary Log.







