---
title: VACUUM
description: Remove unused data files from a Delta, Apache Spark, or Apache Iceberg table directory with the VACUUM command in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/delta-vacuum
---

# VACUUM

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Remove unused files from a table directory.

> [!NOTE]
>
> This command works differently depending on whether you're working on a Delta, Apache Spark, or Apache Iceberg table.

## Vacuum a Delta table

Recursively vacuums directories associated with the Delta table. For full details and limitations, see [Remove unused data files with vacuum](https://docs.databricks.com/aws/en/tables/operations/vacuum.md).

`VACUUM` removes all files from the table directory that are not managed by Delta, as well as data files that are no longer in the latest state of the transaction log for the table and are older than a retention threshold. `VACUUM` will skip all directories that begin with an underscore (`_`), which includes the `_delta_log`. Partitioning your table on a column that begins with an underscore is an exception to this rule; `VACUUM` scans all valid partitions included in the target Delta table. Delta table data files are deleted according to the time they have been logically removed from Delta's transaction log plus retention hours, not their modification timestamps on the storage system. The default threshold is 7 days.

If you run `VACUUM` on a Delta table, you lose the ability to [time travel](https://docs.databricks.com/aws/en/tables/history.md) back to a version older than the specified data retention period.

If [predictive optimization](https://docs.databricks.com/aws/en/optimizations/predictive-optimization.md) is enabled, Databricks automatically triggers the `VACUUM` operation as part of its optimization process. You don’t need to run `VACUUM` manually in most cases.

> [!WARNING]
>
> Databricks strongly recommends setting a retention interval of at least 7 days. If you have jobs that run for several days, long-running jobs might write files that are not yet committed. If your retention period is too short, `VACUUM` could delete these uncommitted files before the job completes.

Delta Lake has a safety check to prevent you from running a dangerous `VACUUM` command. In Databricks Runtime, you are certain that there are no operations being performed on this table that take longer than the retention interval you plan to specify, you can turn off this safety check by setting the Spark configuration property `spark.databricks.delta.retentionDurationCheck.enabled` to `false`.

## Vacuum an Apache Iceberg table

Recursively removes unreferenced files from the directories associated with the Apache Iceberg table. The retention period is fixed at 7 days.

If [predictive optimization](https://docs.databricks.com/aws/en/optimizations/predictive-optimization.md) is enabled, Databricks automatically triggers the `VACUUM` operation as part of its optimization process. You don’t need to run `VACUUM` manually in most cases.

### Syntax

```
VACUUM table_name { { FULL | LITE } | DRY RUN } [...]
```

### Parameters

* [`table_name`](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name)

  Identifies an existing Delta table. The name must not include a [temporal specification or options specification](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name).

* **`DRY RUN`**

  Return a list of up to 1000 files to be deleted.

* **`FULL`** or **`LITE`**

  **Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 16.1 and above

  `FULL` runs the vacuum operation in *Full* mode.
  This deletes data files outside of the retention duration and all files in the table directory not referenced by the table.

  `LITE` runs the vacuum operation in *Lite* mode.
  Instead of finding all files in the table directory, `VACUUM` uses the Delta transaction log to identify and remove files no longer referenced by any table versions within the retention duration.
  If `VACUUM LITE` cannot be completed because the Delta log has been pruned a [DELTA\_CANNOT\_VACUUM\_LITE](https://docs.databricks.com/aws/en/error-messages/error-classes.md#delta_cannot_vacuum_lite) exception is raised.

  The default is `FULL`.

> [!IMPORTANT]
>
> The retention window for the `VACUUM` command is determined by the `delta.deletedFileRetentionDuration` table property, which defaults to 7 days.
> This means `VACUUM` removes data files that are no longer referenced by a Delta table version in the last 7 days.
> To retain data for a longer period, such as to support time travel for longer durations, set this table property to a higher value.
> The following example shows setting this threshold to 30 days:
>
> ```sql
> ALTER TABLE table_name SET TBLPROPERTIES ('delta.deletedFileRetentionDuration' = '30 days');
> ```

## Vacuum other tables

Recursively vacuums directories associated with non-Delta and non-Iceberg tables, removing uncommitted files older than a retention threshold. The default threshold is 7 days.

On these tables, Databricks automatically triggers `VACUUM` operations as data is written.

### Syntax

```
VACUUM table_name
```

### Parameters

* [`table_name`](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name)

  Identifies an existing table by name or path.
