Database restore

On this page 7

A database restore is the process of rebuilding a database from backup copies, and often from archived transaction logs, so that it returns to a known, transactionally consistent state. In Backup & recovery for databases, the restore is the step that turns stored backups into a working system again after hardware failure, corruption, accidental deletion, ransomware or a request for a historical copy.

A backup has value only if it can be restored within the time the business can tolerate. For that reason, experienced administrators treat the restore, not the backup, as the real deliverable, and they measure it against two targets: the recovery time objective (RTO) and the recovery point objective (RPO).

How a database restore works

A database restore usually runs in three phases: copy, roll forward and recover. First, the engine or a backup tool copies data files or replays a logical dump onto the target storage. Second, it applies archived logs to move the data forward in time. Third, it rolls back transactions that were not committed at the chosen point, then opens the database for use.

The roll-forward phase depends on the write-ahead log, called the WAL in PostgreSQL, the binary log in MySQL, the transaction log in SQL Server and redo logs in Oracle. Every committed change is written to this log before it reaches the data files, so replaying the log over an older base backup reconstructs every later commit. Stopping the replay at a chosen timestamp or log position is what makes point-in-time recovery possible.

The table below shows what each phase does and what typically limits its speed.

PhaseWhat happensMain speed limit
Copy or reloadBase backup files are written to disk or a dump is replayedStorage and network throughput
Roll forwardArchived logs are applied in sequenceVolume of log since the base backup
UndoUncommitted transactions are rolled backSize of open transactions
ValidationConsistency checks and application testsDatabase size and test depth
Phases of a typical restore

Restore types and their scope

Restores differ by what source they start from and how much they bring back. The type available is decided at backup time: a restore cannot recover a point in time for which neither a base backup nor a continuous log chain exists.

Restore typeSourceGranularityTypical use
Full restoreFull physical backupWhole instance at backup timeServer loss or rebuild
Point-in-time restoreBase backup plus log chainAny moment in the log rangeUndoing a harmful change
Logical restoreDump from pg_dump or mysqldumpDatabase, schema or tableMigration or selective recovery
Differential or incremental restoreFull backup plus change setsTime of the last change setShorter backup windows
Snapshot restoreStorage or cloud volume snapshotMoment of the snapshotFast rollback of large volumes
Page or file restorePhysical backup plus logsDamaged pages or filesLocalized corruption
Common database restore types

A logical restore replays SQL statements or rows and rebuilds indexes, so it is portable across versions and platforms but much slower for large databases. A physical restore copies data files block by block, which is fast but generally requires the same major engine version and a compatible platform.

A database restore is often confused with neighboring mechanisms that also bring data back. The key difference is that a restore starts from a stored backup, while the others work from a running system or its own logs.

MechanismStarting pointTriggered byProtects against
Database restoreBackup files and archived logsAdministrator or automationLoss, corruption, human error
Crash recoveryData files and the live logEngine at startupPower loss and process crashes
FailoverRunning replicaCluster manager or operatorPrimary server outage
Log shippingContinuously applied log copiesScheduled jobsSite or server loss
Restore and related recovery mechanisms

Replication is not a substitute for a restore. A replica faithfully copies a mistaken DROP TABLE or encrypted ransomware data within seconds, so only an independent backup with a log chain can return the database to the moment before the damage.

Planning a reliable restore

A reliable restore is designed backward from the RTO and RPO. If the business accepts at most fifteen minutes of lost data, logs must be archived at least that often; if the system must be back within one hour, the restore path must be fast enough for the full data volume, including roll forward.

  • Test restores regularly on separate hardware, ideally automated weekly or monthly, and record the measured duration.
  • Verify the full log chain, because one missing log segment stops point-in-time recovery at the gap.
  • Keep an offline or immutable copy so that ransomware or a compromised administrator account cannot delete every backup.
  • Document the runbook, including encryption keys, credentials, target versions and the order of dependent databases.
  • Restore to a separate instance first when recovering a single table, then copy the needed rows back.

Restore speed is dominated by data volume and log volume. As a rough guide, a physical restore runs at the throughput of the slowest link in the storage and network path, while a logical restore of hundreds of gigabytes can take many hours because every index is rebuilt.

Common restore failures and fixes

Most failed restores trace back to untested assumptions made at backup time. The table below lists frequent symptoms seen during real incidents.

SymptomLikely causeRemedy
Recovery stops earlyMissing or corrupted log fileMonitor archive continuity and checksums
Restore takes far longer than RTOLogical dump of a large databaseUse physical backups or snapshots
Backup cannot be decryptedLost encryption key or certificateStore keys separately and test them
Application errors after restoreRelated databases restored to different timesRestore dependent systems to one point
Version mismatch errorTarget engine differs from sourceKeep matching binaries for recovery
Restore problems, causes and remedies

The short version

A database restore is how a system gets its data back from a saved copy. Imagine a writer who saves a copy of a manuscript every night and also keeps a diary of every edit made during the day. If the laptop breaks at noon, the writer takes the nightly copy and repeats the morning edits from the diary.

Databases work the same way. The backup is the nightly copy, and the transaction log is the diary. The essential lesson is that a backup counts only once a restore has been tested.

Where it makes a difference

An online booking service runs a 900 GB PostgreSQL database with a nightly base backup and continuous WAL archiving to separate object storage. At 14:32 on a Tuesday, a developer runs a migration script against production by mistake and deletes the payments history for the current month. The replica copies the deletion immediately, so failover does not help.

The database team restores the previous night’s base backup to a new server, replays the archived WAL and sets the recovery target to 14:31. The physical copy takes about 70 minutes and roll forward about 25 minutes. They export the missing payment rows from the restored instance and load them back into production. The outcome is no lost payments and under two hours of partial disruption, well inside the agreed four-hour RTO.