VACUUM permanently deletes old, unreferenced data files past the retention window (default 7 days) โ reclaiming storage, but ending time travel beyond that point. This deep dive walks the lifecycle and the code.
7-day defaultRETAIN n HOURSDRY RUNLITE / FULLsafety check
The one-liner
VACUUM removes data files no longer referenced and older than the retention threshold (default 7 days). It reclaims storage and finalizes deletes โ but versions older than retention are no longer time-travelable afterward.
๐๏ธ Analogy: VACUUM is emptying the recycle bin. A DELETE just moves old files to "trash" (still time-travelable); VACUUM empties the bin for anything older than retention โ space back, but no more undo for those.
Retention vs time travel โ drag the threshold
โธ files older than retention get purged on VACUUM
7
1 ยท The delete โ vacuum lifecycle
Row removal happens in two stages โ the model interviewers want: a logical tombstone (files stay, still time-travelable, no space freed), then a physical removal by VACUUM once past retention.
DELETE FROM main.sales.events WHERE event_date < '2026-01-01'; -- stage 1: logicalVACUUM main.sales.events; -- stage 2: physical (past retention)
2 ยท DELETE vs VACUUM โ click each
VACUUM main.sales.events RETAIN168HOURS; -- explicit 7-day retentionVACUUM main.sales.events DRY RUN; -- preview what would be purgedVACUUM main.sales.events LITE; -- log-only scan (Public Preview, DBR 16.4 LTS+)
1 ยท DELETE / UPDATE / MERGE / OPTIMIZEโธ
Marks old files "unused" (tombstones) in the log but leaves them on disk. Data is still recoverable via time travel โ nothing is freed yet.
2 ยท VACUUM โฆ DRY RUNโธ
Previews exactly which files would be deleted, without removing anything. Always do this first on important tables.
3 ยท VACUUMโธ
Permanently deletes unused files older than retention. Storage reclaimed; time travel to those versions is now gone. Below-threshold VACUUM is blocked by a safety check.
Files are eligible only past delta.deletedFileRetentionDuration (default 7 days). Databricks blocks a below-threshold VACUUM โ a long-running query started before the VACUUM may still need files you'd delete.
โ ๏ธ Only if you understand the risk. This can break time travel AND corrupt concurrent readers/writers. Keep retention โฅ your longest job runtime.
Tune retention (longer rollback window, more storage)
ALTER TABLE main.sales.events
SET TBLPROPERTIES ('delta.deletedFileRetentionDuration' = 'interval 30 days');
4 ยท Automation & the compliance angle
Predictive Optimization runs VACUUM automatically on UC managed tables โ you often don't schedule it. It does not run automatically otherwise (external tables โ you schedule it).
GDPR / right-to-be-forgotten: a DELETE alone isn't enough โ data persists in old files until VACUUM physically removes it past retention. Pattern: DELETE the records, then ensure VACUUM runs.
Why it matters
Without VACUUM, every rewrite (OPTIMIZE, MERGE, DELETE) leaves stale files โ storage grows forever and listing slows.
"Why can't I VACUUM with 0 retention?" is a classic interview Q โ it would break time travel and can corrupt in-flight concurrent readers/writers.
๐ฝ Real-world use case: a heavily-updated silver table balloons in storage. A scheduled VACUUM (7-day retention) clears stale files nightly โ keeping a week of rollback while controlling cost.
Edge case: VACUUM shrinks the time-travel window; LITE mode (Public Preview, DBR 16.4 LTS+) is faster but needs a prior successful VACUUM within log retention. Always DRY RUN first.
Limitation: only removes files past retention โ it won't instantly free space from a 5-minute-old delete; lowering retention to force it trades away time travel and risks concurrent readers.
Common gotchas
โ Setting retention to 0 to "save space now" โ breaks time travel & can corrupt concurrent reads; blocked by default.
โ Expecting time travel to reach old versions after VACUUM โ it can't.
โ Surprised storage didn't drop โ only files older than retention are removed.
โ Assuming DELETE alone satisfies GDPR โ you must VACUUM to physically remove.