- Replicas are designed to keep a copy of the primary as closely synchronized as possible. They receive changes from the primary (commonly via WAL/transaction streaming) and apply them automatically.
- When the primary deletes 10 million rows, the replicas receive and apply that same DELETE almost immediately. Replication applies the primary’s changes deterministically and does not evaluate whether an operation was intended or accidental.
- By the time someone notices the mistake, replicas will most likely have the same missing data.
- A replica that is significantly behind (replication lag) and has not yet received the DELETE.
- Replication that was paused or stopped before the DELETE arrived. These are edge cases and unreliable to depend on as a recovery strategy.
Replication protects availability and failover — it helps keep your service online if the primary fails. It is not a substitute for backups when protecting against human error or logical corruption.
- Regular, off-host backups/snapshots stored in durable object storage (for example, Amazon S3) or another immutable/offsite location.
- WAL (PostgreSQL) or binary log (MySQL) archiving to enable point-in-time recovery (PITR).
- A documented and tested restore procedure: restore the backup, then replay WAL/binlogs up to just before the bad operation.
High-level recovery workflow (recommended)
- Restore the most recent backup/snapshot to an isolated instance.
- Replay WAL/binlogs up to the timestamp or LSN just before the accidental DELETE (PITR).
- Validate the recovered data, then:
- Bring the recovered instance into production, or
- Extract only the missing rows and re-insert them into the live database after verification.
- Restore base backup.
- Set
recovery_target_timeorrecovery_target_lsninrecovery.conf(or usepg_restore/pg_basebackupworkflows). - Start recovery and stop at the target time/LSN, then validate.
- Keep frequent backups and retain them for a period that matches your business’s RPO/RTO requirements.
- Archive WAL/transaction logs continuously and ensure the archive is tested and restorable.
- Regularly run simulated restores (drills) to confirm you can recover within your desired window.
- Monitor replication lag — while you shouldn’t rely on lag for recovery, knowing replica lag can help in emergency triage.
Backups should be regular, stored off the live system, and you should routinely test restores. Without backups and WAL/transaction log archiving, replicas cannot save you from accidental deletes.