Database snapshot

On this page 7

A database snapshot is a point-in-time image of a database’s data that can be read, copied or restored later as if the database had been frozen at that moment. In backup & recovery for databases, snapshots provide fast, low-impact recovery points and quick clones, because they are usually created in seconds by recording changes rather than copying every data page.

The term covers several mechanisms: storage-level snapshots of the volume that holds the data files, cloud-managed snapshots of a database instance, and engine-level snapshots, such as the read-only database snapshots in SQL Server. They share the point-in-time idea but differ sharply in consistency, location and durability.

How a database snapshot captures a point in time

A database snapshot captures a point in time by preserving the original version of every block that changes after the snapshot is taken, instead of copying all data up front. Two techniques dominate: copy-on-write, which copies the old block aside before it is overwritten, and redirect-on-write, which writes the new block to a fresh location and leaves the original in place.

Because only changed blocks consume new space, creating a snapshot takes seconds regardless of database size, and its storage cost grows with the rate of change, not with the total volume. A 2 TB database that changes 3 percent per day adds roughly 60 GB of snapshot space per day.

The difficult part is consistency. A database writes data files and the write-ahead log at different moments, so a snapshot taken mid-write captures a state that looks like a sudden power loss. Crash recovery normally repairs this on restore, but only if all files, including the log, are captured at the same instant.

Consistency levels of database snapshots

The value of a snapshot depends on how consistent the captured state is. The following levels describe what a restore will find.

LevelHow it is achievedState after restore
InconsistentVolumes snapshotted at different momentsMay be unrecoverable or silently corrupt
Crash-consistentAll volumes captured atomicallyRecovers like after a power failure
Application-consistentDatabase told to flush and pause writes firstClean state, no crash recovery needed
Transaction-consistentEngine-level snapshot of committed dataOnly committed transactions visible
Snapshot consistency levels

Crash-consistent snapshots are adequate for most modern engines with write-ahead logging. When data and log sit on separate volumes, the snapshot must use a consistency group or the database must be quiesced, for example with a backup mode or a brief write freeze.

Database snapshot compared with other backup methods

A database snapshot is one recovery tool among several, and a sound backup strategy combines it with others because each covers a different failure.

MethodWhat it capturesRestore granularityMain limitation
Database snapshotBlock-level image at one momentWhole database or volumeOften on the same storage as the data
Database dumpLogical SQL or object exportSingle tables or rows possibleSlow for large databases
Physical backupCopy of data files plus logWhole instanceTime and space proportional to size
Binary log or WAL archiveStream of every changeAny moment, combined with a baseUseless without a base backup
Point-in-time recoveryBase backup replayed with logsAny second within retentionRestore time grows with log volume
Snapshots and neighboring backup methods

Snapshots excel at recovery speed, often restoring or cloning a multi-terabyte database in minutes. Dumps excel at portability and selective restore. Log archives provide recovery to any moment between snapshots, which snapshots alone cannot.

Using database snapshots in practice

Database snapshots are most useful before risky changes, for frequent recovery points and for creating test copies. Typical scheduling and retention follow the recovery objectives of the system.

UseTypical frequencyTypical retention
Pre-change safety pointBefore each migration or upgradeHours to a few days
Routine recovery pointsEvery 1 to 24 hoursDays to weeks
Development and test clonesOn demandUntil the test ends
Long-term retentionDaily or weekly, copied off-siteMonths to years
Common snapshot uses and settings

Snapshots kept only on the primary storage system protect against logical errors, such as a faulty migration, but not against loss of that storage system. Copying snapshots to a separate account, region or storage tier turns them into genuine backups.

Limitations and common mistakes

The convenience of snapshots invites assumptions that fail during a real recovery. Each item below has caused data loss in otherwise well-run environments.

  • Treating local snapshots as backups, although they share hardware and credentials with the data.
  • Snapshotting data and log volumes separately, which yields an inconsistent image.
  • Keeping long chains of copy-on-write snapshots, which degrades write performance on some storage systems.
  • Restoring a snapshot onto a replica set without rebuilding replication, which causes diverging copies.
  • Never testing restores, so the team discovers missing volumes or keys only during an incident.

Encryption adds another dependency: a snapshot of an encrypted volume is unusable without the key, so key retention must match snapshot retention.

In plain words

A database snapshot is like a photograph of a whiteboard. It is taken just before someone starts rewriting the board. If the new writing goes wrong, you look at the photo. Then you put everything back exactly as it was.

The photo is almost instant. The system only keeps the parts that change afterward. The weakness is where the photo is kept: often in the same room as the whiteboard. If the room burns down, both are lost. Important photos must therefore also be stored somewhere else.

A real-world example

An e-commerce team plans a schema migration that rewrites the main orders table of a 1.5 TB database during a night maintenance window. A traditional full backup would take several hours, longer than the window.

Instead, the operator stops application writes, takes a crash-consistent snapshot of the data and log volumes as one consistency group, and starts the migration. The snapshot completes in under a minute. Halfway through, a data conversion error appears. The team restores the snapshot, which brings the database back in about 15 minutes, and reopens the shop on schedule. The same evening, a copy of the snapshot is already replicated to another region, so the recovery point also protects against a storage-level failure.