Delta Lake interview questionsQuestion 7 of 8
Delta Lake interview question · Question 7 of 8
What does VACUUM do in Delta Lake, and what can go wrong?
Short answer
VACUUM permanently deletes data files that the current version of the table no longer uses and that are older than the retention period, 7 days by default. It also removes leftover files from failed writes, but never touches the transaction log. After it runs, time travel and RESTORE to versions that needed those files fail, and queries or streams still reading an older snapshot can hit missing files. Delta blocks a shorter retention unless you turn off a safety check. Set the retention longer than your longest-running query, your maximum stream delay and the restore window you promise.
Detailed explanation
DELETE, UPDATE, MERGE, OPTIMIZE and overwrites never delete data files; they add remove actions to the log, so older versions can still read the files. VACUUM is the step that actually frees the storage. It deletes files that are:
- not referenced by the current version, and
- older than the retention threshold.
It is not automatic in open-source Delta; schedule it. VACUUM ... DRY RUN lists what would be deleted. VACUUM LITE (Delta 3.3 and later) finds candidates from the log rather than listing the whole directory, which is much cheaper on large object-store tables.
Example
In a local test, t.vacuum(0) failed with DELTA_VACUUM_RETENTION_PERIOD_TOO_SHORT. After disabling spark.databricks.delta.retentionDurationCheck.enabled and running VACUUM ... RETAIN 0 HOURS, the current version still read correctly, but reading version 0 failed with FAILED_READ_FILE.FILE_NOT_EXIST.
VACUUM events DRY RUN; -- inspect first
VACUUM events; -- default 7-day retention
ALTER TABLE events SET TBLPROPERTIES ('delta.deletedFileRetentionDuration' = 'interval 14 days');
Trade-offs and pitfalls
- Long readers and streams. A job that started before a compaction still reads the pre-compaction files; a lagging stream may need files from days ago. Retention must cover both.
- Restore window. If you promise “we can roll back a week”, keep at least a week, and keep
delta.logRetentionDuration(30 days by default) at least as long. - Cost. Longer retention keeps more removed files in storage, especially on tables rewritten often by
MERGEorOPTIMIZE. - Erasure. With deletion vectors, deleted rows remain in the Parquet files until they are rewritten (
REORG TABLE ... APPLY (PURGE)or compaction); only then canVACUUMremove the old files after the retention period.
Common mistakes
- Disabling the retention check to “save storage” while jobs are running.
- Assuming a
count()on an old version proves its files exist; Delta can answer it from log statistics without opening files. - Treating time travel as long-term backup.
Progress is saved in this browser only. No account needed.

