(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to run VACUUM on a Delta table in Fabric Lakehouse

João Barros 10 de July de 2026 4 min read

As you update, delete and optimize a Delta table in the Lakehouse, data files that no longer belong to the current version of the table pile up while still taking space in OneLake. The VACUUM command exists precisely to clean up those old files in a controlled way, reclaiming storage without touching the current data. Below you will see how to run VACUUM on a Delta table in the Lakehouse safely, starting with a DRY RUN before deleting anything.

Prerequisites

  • A Microsoft Fabric workspace with an active capacity.
  • A Lakehouse with at least one Delta table where you have already run operations such as UPDATE, DELETE, MERGE or OPTIMIZE.
  • A Fabric notebook attached to that Lakehouse to run Spark SQL or PySpark.
  • Basic SQL knowledge.

Step 1: Understand why extra files exist

Whenever you run an UPDATE, DELETE, MERGE or OPTIMIZE, Delta does not change the existing files: it writes new Parquet files and marks the old ones as removed in the transaction log. The old files stay physically in place so that time travel keeps working. Over time they build up and increase storage cost, even when the table has few rows.

This build-up is exactly what VACUUM solves: it removes files that are no longer referenced by the current version and that are older than the retention window.

Step 2: Simulate the cleanup with DRY RUN

Before deleting anything, use the DRY RUN option. It shows the list of files that would be removed, without deleting them. It is the safest way to understand the impact of the command.

-- Lists the files that would be removed, without deleting anything
VACUUM vendas RETAIN 168 HOURS DRY RUN

Replace vendas with your table name. If the list comes back empty, there are no files old enough to clean up — and that is perfectly normal.

Step 3: Run VACUUM with the default retention

Once you are comfortable with the DRY RUN output, run VACUUM without that option. If you do not provide an interval, Delta uses the default retention of seven days (168 hours), meaning it keeps everything that might be needed to read versions from the last week.

-- Removes files older than 7 days that are no longer referenced
VACUUM vendas

The command returns the table path and cleans up the eligible files. It is safe to run several times: if there is nothing to remove, it does nothing.

Step 4: Shorten the retention window (carefully)

Sometimes you want to reclaim space faster and shorten retention to less than seven days. Delta has a safety check that blocks this by default, because deleting recent files can break time travel and affect ongoing reads. Only disable it if you understand the impact.

-- Use only when you understand the effect on time travel
SET spark.databricks.delta.retentionDurationCheck.enabled = false;
VACUUM vendas RETAIN 24 HOURS;
Warning: never use RETAIN 0 HOURS on a table with concurrent writes — you may delete files still in use and lose data. In production, keep the default retention whenever possible.

Step 5: The PySpark alternative

If you prefer to work in Python, the DeltaTable API does the same as the SQL command. It is handy when you want to fold the cleanup into an existing maintenance notebook.

from delta.tables import DeltaTable

dt = DeltaTable.forName(spark, "vendas")
dt.vacuum()        # default retention of 168 hours
# dt.vacuum(168)   # the same, but explicit in hours

Check the result

To confirm that VACUUM ran, look at the table history. You will see VACUUM START and VACUUM END operations logged with their date and time.

DESCRIBE HISTORY vendas

You may also notice that the space used by the table folder in OneLake has dropped. If you try to time travel to a version older than the retention you set, that read will fail — which is the expected behaviour after cleaning up the files.

Conclusion

VACUUM is the final piece of a good maintenance routine: first you compact files with OPTIMIZE, then you reclaim space with VACUUM. In Fabric you can run these commands manually in a notebook or use the Lakehouse table maintenance feature to schedule them. Start with the default retention, watch the history for a few weeks, and only then consider adjusting the window. Which table in your Lakehouse has been growing the most — and do you know how long it has been since it last had a VACUUM?