VACUUM LITE in Delta Lake and Databricks: Faster Cleanup, and When It Fails
What VACUUM does to a Delta table, how VACUUM LITE finds old files from the transaction log instead of listing storage, the one case where it fails, how retention and time travel interact, and when you need neither because predictive optimization runs it for you.
Tecyfy · Published · Updated · 5 min read
VACUUM deletes the data files a Delta table no longer needs. VACUUM LITE does the same job faster: instead of listing every file in the table's folder, it reads the Delta transaction log to find which files were removed and when. It arrived in open-source Delta Lake 3.3 and in Databricks Runtime 16.1. The catch is that LITE only works while the log still covers the time since the last vacuum.
Why Delta tables need vacuuming
A Delta table never changes a data file in place. An UPDATE, MERGE, DELETE or OPTIMIZE writes new files and records in the transaction log that the old ones are no longer part of the table. The old files stay in storage so readers can still query earlier versions (time travel) and so a long-running query is not pulled out from under.
Left alone, those files pile up and you keep paying to store them. VACUUM deletes the ones that were removed from the table longer ago than the retention period, 7 days by default. It goes by when a file was removed in the log, not by the file's timestamp in storage.
FULL and LITE
VACUUM (FULL, the default) | VACUUM LITE | |
|---|---|---|
| How it finds files | Lists every file in the table folder and compares with the log | Reads the transaction log only |
| Removes | Old removed files and any file the table never referenced (failed writes, stray copies) | Old removed files only |
| Speed on large tables | Slow: listing millions of objects in cloud storage takes time | Faster, because no listing is needed |
| Can fail when | Rarely | The log no longer covers the period since the last vacuum |
FULL is what you get when you write plain VACUUM. LITE is the one to run often; FULL is the one to run now and then to sweep up files the log has never heard of, such as the leftovers of a write that crashed.
Running it
-- See what would go, without deleting anything (lists up to 1,000 files)
VACUUM sales.orders LITE DRY RUN;
-- Delete files removed from the table more than 7 days ago
VACUUM sales.orders LITE;
-- The occasional full sweep
VACUUM sales.orders FULL;
Open-source Delta Lake takes a retention in the command too, and can read the file list from an inventory table instead of listing storage:
VACUUM sales_orders LITE RETAIN 168 HOURS;
VACUUM sales_orders USING INVENTORY inventory_table;
In Python, DeltaTable.forName(spark, "sales.orders").vacuum() runs a vacuum with the default retention.
When LITE fails
Delta deletes old transaction log entries on its own, after 30 days by default. LITE needs the log entries that describe every removal since the last successful vacuum. If no vacuum has run within the log's retention, those entries are gone and LITE stops with DELTA_CANNOT_VACUUM_LITE.
The fix is simple: run one VACUUM FULL, then schedule LITE often enough (weekly is plenty with the defaults) that the log always covers the gap.
Retention and time travel
Vacuuming is what ends time travel. After a vacuum with 7-day retention, versions older than 7 days can no longer be read, because their files are gone.
To keep more history, raise the retention on the table rather than skipping vacuums:
ALTER TABLE sales.orders
SET TBLPROPERTIES ('delta.deletedFileRetentionDuration' = '30 days');
Going the other way, below 7 days, is blocked by a safety check. You can turn it off with spark.databricks.delta.retentionDurationCheck.enabled = false, but only do so if nothing that reads or writes the table ever runs longer than the new retention. Otherwise a running job can find its files deleted mid-read. Databricks strongly recommends keeping at least 7 days.
Do you need to run it at all?
On Databricks, often not. Predictive optimization runs VACUUM automatically on Unity Catalog managed tables, along with OPTIMIZE, so manual vacuum jobs are usually unnecessary there. Run it yourself for external tables, tables without predictive optimization, and open-source Delta Lake.
When you do run it yourself:
- Run it regularly on every table: unvacuumed tables are a quiet storage bill.
- Size the compute modestly. Databricks suggests autoscaling between 1 and 4 workers with 8 cores each, and a driver with 8 to 32 cores, since much of the work is deleting files.
- Use LITE for the regular job and FULL for an occasional sweep.
Tecyfy Takeaway
VACUUMdeletes files a Delta table removed more than 7 days ago; it is what keeps storage costs down and what ends time travel.VACUUM LITEreads the transaction log instead of listing storage, so it is faster for regular cleanup, but leaves untracked files and fails if no vacuum ran within the log's 30-day retention.- On Unity Catalog managed tables with predictive optimization, Databricks vacuums for you.
- Change history length with
delta.deletedFileRetentionDuration, not by skipping vacuums.
For the other half of Delta table upkeep, see our guide to liquid clustering and the Databricks performance checklist.
Questions
- What is VACUUM LITE in Delta Lake?
- VACUUM LITE deletes the data files a Delta table no longer needs by reading the transaction log, instead of listing every file in the table's folder. It is faster on large tables. It arrived in Delta Lake 3.3 and Databricks Runtime 16.1.
- What is the difference between VACUUM LITE and VACUUM FULL?
- FULL, the default, lists every file in storage and also removes files the table never referenced, such as leftovers of a failed write. LITE reads only the log and removes only files the table removed. Run LITE often and FULL now and then.
- Why does VACUUM LITE fail with DELTA_CANNOT_VACUUM_LITE?
- LITE needs the log entries for every removal since the last vacuum, and Delta deletes log entries after 30 days by default. If no vacuum ran within that time, run one VACUUM FULL, then schedule LITE often enough, weekly is plenty, that the log always covers the gap.
- How long does VACUUM keep old files?
- 7 days by default, counted from when a file was removed in the log. Versions older than the retention can no longer be read with time travel. To keep more history, raise delta.deletedFileRetentionDuration on the table.
- Do I need to run VACUUM on Databricks?
- Often not. Predictive optimization runs VACUUM automatically on Unity Catalog managed tables. Run it yourself on external tables, tables without predictive optimization and open-source Delta Lake.
Sources