Recover Database Using Archive Log Files
- Total recovery data (GB)
- GB
- Result
- Target time (minutes after backup)
- 120 min
- You entered
- Redo rate (KB per minute)
- 50 KB/min
- You entered
Yes, you can recover a database using archive log files. Archive logs record every change made to the database, and when combined with a full or incremental backup, they allow you to roll a database forward to a specific point in time—often the exact moment just before a failure or an accidental data deletion. This article explains what archive logs are, how the recovery process works, the commands involved, and the common pitfalls to avoid.
Formula
The calculator estimates how much archive log data you need to recover a database to a target time after your last backup. The formula is:
Archive logs needed (MB) = (target minutes × redo rate in KB/min) / 1024
Where:
- Target time (t) – minutes between the backup and the point you want to recover to.
- Redo rate (r) – how fast the database generates redo/archive data, in kilobytes per minute.
- Backup size (b) – size of the full backup in gigabytes, used to estimate total recovery data.
Total recovery data = backup size + archive logs (converted to GB). This gives you a rough idea of storage and transfer requirements.
Worked Example
Using the defaults: target time = 120 minutes, redo rate = 50 KB/min, backup size = 10 GB.
Archive logs needed = (120 × 50) / 1024 = 6000 / 1024 = 5.86 MB (rounded to 2 decimals).
Total recovery data = 10 + (5.86 / 1024) = 10 + 0.0057 = 10.01 GB.
So after a 2-hour gap, you need about 5.86 MB of archive logs and about 10.01 GB of total data to restore.
What Are Archive Log Files?
Archive log files are copies of filled online redo log files. In databases like Oracle, PostgreSQL (WAL files), SQL Server (transaction log backups), and MySQL (binlogs), the database writes every committed transaction to a redo log. When that log fills up, instead of overwriting it, you can copy it to a safe location—that copy is an archive log.
These files form a continuous sequence of changes. If you have a full backup from Monday and archive logs from Monday to Friday, you can replay those logs on the backup to bring the database to any point on Friday. Without archive logs, you can only restore to the moment of the backup, losing all subsequent transactions.
How Recovery Works
Recovery using archive logs follows a standard sequence:
- Restore the last full backup – copy the backup files to the database data directory.
- Apply incremental backups (if any) – these reduce the number of logs needed.
- Apply archive logs in order – starting from the backup’s SCN (system change number) or LSN (log sequence number), replay each archived log.
- Stop at the desired point – either the end of the logs (complete recovery) or a specific time/transaction (point-in-time recovery).
In Oracle, you would use RECOVER DATABASE UNTIL TIME '...' or RECOVER DATABASE USING BACKUP CONTROLFILE. In PostgreSQL, you set restore_command in recovery.conf (or postgresql.conf in newer versions) to fetch WAL files. In SQL Server, you restore the full backup with NORECOVERY, then apply log backups with RESTORE LOG ... WITH RECOVERY.
Choosing the Right Recovery Point
The most common reason to recover with archive logs is to undo an accidental DELETE, DROP, or bad update. To do that, you must know the exact time or transaction ID of the mistake. If you don’t, you may have to restore to multiple candidate points and inspect the data.
For example, if a user ran DELETE FROM orders at 14:32, you would recover to 14:31:59. If you recover to 14:32:01, the deletion is still there. Some databases allow you to use a restore point or a guaranteed restore point (Oracle) to make this easier.
If you are recovering to the last committed transaction (complete recovery), you simply apply all available logs. This is the most common scenario after a hardware failure or a corrupted data file.
Common Problems and How to Avoid Them
- Missing archive logs – if a log is lost (e.g., disk failure), recovery stops. Solution: keep multiple copies, use a fast recovery area, and test restores regularly.
- Wrong sequence – applying logs out of order causes errors. Always apply in SCN/LSN order.
- Time zone confusion – when using
UNTIL TIME, ensure you use the database’s time zone, not your local one. - Incorrect backup type – a differential backup may not include all changes since the last full backup. Read the backup documentation.
- Not enabling archiving – if the database runs in NOARCHIVELOG mode (Oracle) or without WAL archiving (PostgreSQL), you have no logs to replay. You must enable archiving before you need it.
Costs and Storage Considerations
Archive logs consume disk space. A busy database can generate gigabytes per hour. You need to decide how long to keep them—long enough to recover to a reasonable point, but not so long that you run out of storage. Many organizations keep 1–7 days of logs, plus a daily backup. Cloud storage is a common destination for off-site archives.
Recovery time also matters: replaying logs is I/O intensive. If you have 100 GB of logs, recovery may take hours. Using incremental backups reduces the number of logs you must apply.
Alternatives to Archive Log Recovery
If you don’t have archive logs, your options are limited:
- Standby database – a continuously updated copy that can be activated quickly.
- Flashback technology – Oracle Flashback Database or SQL Server temporal tables allow you to rewind without full recovery.
- Point-in-time snapshots – storage-level snapshots are fast but may not be transaction-consistent.
These alternatives are complements, not replacements. Archive logs remain the fundamental safety net for any serious database.
Frequently Asked Questions
Q: Can I recover without a full backup if I have all archive logs?
No. Archive logs are incremental changes; they require a base backup to apply to. Without a base, you have nothing to replay them on.
Q: How long do I need to keep archive logs?
It depends on your recovery point objective (RPO). If you want to lose at most 15 minutes of data, you need at least 15 minutes of logs after your last backup. In practice, keep enough to cover your backup frequency plus a buffer for mistakes.
Q: What is the difference between redo logs and archive logs?
Redo logs are the current, active logs that the database writes to. When they fill, they can be overwritten (if archiving is off) or copied to become archive logs (if archiving is on). Archive logs are the permanent, preserved copies.
Q: Can I recover to a specific transaction, not just a time?
Yes, most databases support recovery to a transaction ID or SCN. Oracle has UNTIL SCN, SQL Server has STOPBEFOREMARK, PostgreSQL has recovery_target_xid. You need to know the transaction ID from the logs.
Q: What happens if an archive log is corrupted?
Recovery will fail at that point. You may be able to skip the corrupted log if you have a later backup that includes those changes, but you will lose data. Regular backup validation is essential.
Q: Is archive log recovery the same as point-in-time recovery?
Point-in-time recovery is a specific type of archive log recovery where you stop at a chosen time. Complete recovery (applying all logs) is another type. Both use the same mechanism.
Related
Formula used
in t | Target time (minutes after backup) | min | 120 | 0 in r | Redo rate (KB per minute) | KB/min | 50 | 0 in b | Backup size (GB) | GB | 10 | 0 out logs | Archive logs needed (MB) | MB | (t * r) / 1024 | 2 out total | Total recovery data (GB) | GB | b + ((t * r) / 1024 / 1024) | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.