The pool is at 94 percent. Somebody asks which snapshots to delete. The usual answer is “the old ones,” which is a guess, and the USED column in zfs list -t snapshot will not rescue you, because it lies by omission. It shows only the space unique to that one snapshot. Blocks shared by two adjacent snapshots are counted against neither.
Two commands fix this. Neither is obscure. Both get skipped.
Start with the space breakdown
zfs list -o space -r tank
-o space is a shorthand column set. You get NAME AVAIL USED USEDSNAP USEDDS USEDREFRESERV USEDCHILD, and the split is the whole point:
USEDDSis what the dataset’s live data takes.USEDSNAPis what would be freed if you destroyed every snapshot on it.USEDREFRESERVis space held back by arefreservation.USEDCHILDis the children’s problem, not this dataset’s.
If USEDSNAP is tiny, deleting snapshots will not save you and you should stop hunting there. If it is most of USED, you found it. That one table settles a surprising number of arguments. The related case where du and df disagree is in the full disk with no files.
Why the per-snapshot USED column misleads
Say you have @mon, @tue, @wed, and a 200 GB file that existed at @mon and @tue and was deleted before @wed. Both earlier snapshots reference the blocks. Neither one’s USED shows them, since each is “shared.” Destroy only one and you free nothing. Destroy both and 200 GB comes back.
So the sort-by-USED-and-delete-the-biggest approach is wrong in exactly the case where it matters, which is a large deletion captured by several snapshots.
Ask the system: destroy with -n and -v
zfs destroy -nv tank/data@mon%wed
-n is a dry run, -v prints what it would do. The % is the range syntax: every snapshot from @mon through @wed inclusive. On OpenZFS this prints the snapshots it would remove and a would reclaim line with the total. That total accounts for the shared blocks properly, because the filesystem computes it across the whole range.
Try a few ranges. Walk the end point forward:
zfs destroy -nv tank/data@mon%tue
zfs destroy -nv tank/data@mon%wed
zfs destroy -nv tank/data@mon%thu
The number jumps at the snapshot where the shared blocks finally have no remaining reference. That jump is the snapshot you needed to know about. Check zfs-destroy(8) on your release for the exact output format and whether -p gives you machine-readable numbers, because I am not going to promise column layouts from memory.
When the numbers say what you want, drop the -n. Keep -v on so the log shows what went.
Scripting it without shooting yourself
A destroy that is wrong cannot be undone. A few habits:
- Run the dry run and the real command from the same shell history entry, same arguments, so a typo cannot differ between them.
- Never build a snapshot name with a variable that might be empty.
tank/data@with nothing after it is a bad day. Useset -uand quote. - Take a hold on anything replication still needs. A held snapshot refuses to be destroyed, which is the correct behaviour for the snapshot your replica’s incremental base depends on.
- If you are unsure about a whole destroy run, a pool checkpoint is the heavy-handed undo. It has its own costs, so read that one first.
One more column: written
zfs list -o name,written,used -t snapshot -r tank/data
written is the data written since the previous snapshot. It answers “which day was the churn,” which is a different question from “what do I get back if I delete this.” Both are useful. They are not the same number, and mixing them up is how people delete the wrong week.
When it still will not free space
If you destroy snapshots and AVAIL barely moves, look at USEDREFRESERV and at clones. A snapshot with a dependent clone cannot be destroyed until the clone is, and the dry run will complain about it instead of quietly doing nothing. Reservations hold space the pool will not hand out to anyone else, so check them before blaming the snapshots.
I learned this the usual way, deleting the oldest eleven snapshots on a Friday and watching the free space move by a few hundred megabytes. The big deletion was in the middle. The disk story that went with it is somewhere in the one where the disk had space and nothing would write. More in the ZFS and storage hub.
