Lesson 4 of 9 · 27m
Snapshot Consistency: Crash, Filesystem, and Application Semantics
Understand what snapshots actually freeze, how write caches and database transactions behave, and how to capture restore points that applications accept.
A snapshot is a photograph of blocks, not a promise that the application understood the photograph. Many restore failures are consistency failures: every file exists, every checksum matches, and the database still refuses to start because the capture sliced through in-flight writes. The most important sentence in backup engineering is this: consistency is defined by the consumer of the data. Crash-consistent copies are sometimes enough because databases and modern filesystems are designed to recover from crashes, but sometimes is not a design.
Three consistency levels
crash-consistent like power was cut at one instant
filesystem-consistent filesystem metadata and dirty pages coordinated
application-consistent application completed or safely recorded transactionsYou must test whether the application can replay journals, redo logs, or transaction logs from that state — especially under real write load.
Filesystem freeze is necessary but not sufficient
Linux exposes filesystem freezing through fsfreeze:
fsfreeze --freeze /var/lib/postgresql
# take disk/LVM snapshot here
fsfreeze --unfreeze /var/lib/postgresqlThis pauses filesystem write completion, but it does not teach PostgreSQL what backup boundary you intended. Hold the freeze as briefly as possible, automate unfreeze with traps, and never use freeze alone as a substitute for database-aware backup mode.
PostgreSQL knows how to be backed up
Use the database's own consistency machinery. A physical backup commonly uses pg_basebackup plus WAL archiving:
pg_basebackup -D /backup/pg-base -U backupuser --wal-method=stream --checkpoint=fastMySQL and InnoDB need care too
mysqldump --single-transaction gives a consistent logical view for InnoDB without a long global write lock; non-transactional tables and transaction pressure still require care, which is why physical tools such as Percona XtraBackup exist:
mysqldump --single-transaction --routines --events --triggers \
--result-file=/backup/appdb.sql appdbVM and volume snapshots need orchestration
Cloud volume snapshots are excellent building blocks, especially when copy time matters. But orchestration must answer: was the application told, was the filesystem frozen, were multiple disks captured as a group, and can every dependent disk be restored to the same logical point? A web root from 02:01 and a database disk from 02:07 are not one backup.
Test consistency under write load
Do not validate snapshot semantics on an idle test VM. Generate representative writes, snapshot mid-stream, restore elsewhere, and inspect application integrity:
pgbench -c 8 -T 120 appdbCompare row counts, constraints, checksums where available, and application-level invariants; PostgreSQL startup is a good sign, not proof.
Field notes
- LVM snapshots can degrade write performance because of copy-on-write overhead; capacity planning is part of correctness.
- Databases can recover from crash-like copies until they cannot; test at production-like concurrency and size.
- Multi-disk consistency groups matter for databases with separated data, WAL, and backup tablespaces.
Was this lesson helpful?