Forum Discussion

amaaiia's avatar
amaaiia
Skilled Sharer
2 years ago
Solved

Delta Lake VACUUM, how does it work?

I don't have very clear how VACUUM command works. Reading documentation, I see that this command removes parquet files that are not being used for versions above the retention period, but I'm testing...
  • frithjof_v's avatar
    2 years ago

    I'm new to Delta Lake, but I think this link explains what the vacuum retention threshold means:

    https://docs.databricks.com/en/delta/vacuum.html#example-syntax-for-vacuum

     

    "Use the RETAIN keyword to specify the threshold used to determine if a data file should be removed. The VACUUM command uses this threshold to look back in time the specified amount of time and identify the most recent table version at that moment. Delta retains all data files required to query that table version and all newer table versions."

     

    My interpretation:
    When we vacuum a table at 2024-04-16 13:29:00 with a retention threshold of 7 days, then we basically tell the vacuum operation to look back to the timepoint 2024-04-09 13:29:00 and identify what was the most recent table version (the "active" table version) at the timepoint 2024-04-09 13:29:00.

    In your case, at that timepoint, I think your version 1 was the most recent version of the table. So the parquet files needed to query version 1 of the table will not be deleted.
    If there existed any parquet files which were only needed for querying version 0 (but not needed for querying version 1 or more recent versions), then I think those parquet files would have been deleted. 

      

    I think if you go to the Lakehouse explorer, and click on the ellipsis (...) next to the table name, and then "View files", you should see the actual parquet files which are still existing.


    If any parquet files were deleted by the vacuum operation, then I think you will not be able to find those parquet files here anymore.

    However, I think the version history of your delta table may still contain references to deleted parquet files.
    This depends on the log history retention period, if I understand correctly (see next comments).

     

    When you use 

     

     

    %%sql
    DESCRIBE HISTORY table_name;

     

     

    I think the history can still include references to some parquet files which are now deleted, because the history log is not deleted by the vacuum operation (see next comments). However the actual data files (parquet files) in your lakehouse table's file directory should be deleted by vacuum operations (according to vacuum retention threshold).