What you will be able to do
- Explain why a Delta DELETE does not remove data from storage, and which retention settings control how long it stays
- Run VACUUM (with DRY RUN) and configure deletedFileRetentionDuration, or rely on predictive optimization for Unity Catalog managed tables
- Purge soft-deleted rows on tables with deletion vectors using REORG TABLE ... APPLY (PURGE) followed by VACUUM
1.Why a DELETE is not yet an erasure
A Delta DELETE writes a new table version. The current version no longer contains the user, but the data files behind earlier versions are still in cloud storage, and anyone who can query the table can travel back to them.
SELECT * FROM people10m VERSION AS OF 123;Querying an old version needs both its log entries and its data files. Two separate settings control how long each of those is kept, and confusing them is the most common mistake in this topic.
| Table property | What it controls | Default | Removed by |
|---|---|---|---|
| delta.logRetentionDuration | How long table history (the transaction log) is kept | interval 30 days | Automatic, asynchronous cleanup after checkpoints, not VACUUM |
| delta.deletedFileRetentionDuration | The threshold VACUUM uses to remove data files no longer referenced in the current table version | interval 7 days | VACUUM |
For erasure, the data files are what matter. Even after log entries expire, the files holding the deleted records stay in cloud storage until something removes them. That is why datasets need regular maintenance to remove previous versions of the data.
Checkpoint 1 of 6· Check yourself
Which process physically removes the data files that still hold a deleted customer's records?
Log files are cleaned up automatically after checkpoints and are not governed by VACUUM. Removing the unreferenced data files is VACUUM's job, and it does so using the deletedFileRetentionDuration threshold.
“Log files are deleted automatically and asynchronously after checkpoint operations and are not governed by VACUUM.”Source: docs.databricks.com
2.VACUUM and predictive optimization on Unity Catalog managed tables
VACUUM removes data files that the table no longer references and that are older than the retention threshold. The files it removes may contain modified or deleted records, so running it regularly is both a cost measure and a compliance measure. The clock starts when a file was logically removed from the transaction log, not at the file's modification time in storage. After VACUUM, you can no longer time travel to versions older than the retention period.
The Unity Catalog route is predictive optimization. It runs VACUUM automatically on Unity Catalog managed tables, and Databricks recommends enabling it on all of them. Lakeflow pipelines also maintain their own streaming tables and materialized views. If predictive optimization isn't enabled, they run maintenance within 24 hours of an update. Outside those two cases, you run VACUUM yourself.
VACUUM table_name DRY RUNDRY RUN returns a list of up to 1000 files that would be deleted. The retention window comes from delta.deletedFileRetentionDuration, which defaults to 7 days. Raising it gives you longer time travel. It also keeps erased records in storage longer and increases storage cost, which matters when you have a one-month deadline to meet.
ALTER TABLE table_name SET TBLPROPERTIES ('delta.deletedFileRetentionDuration' = '30 days');Lowering the threshold below 7 days is possible but risky. Databricks strongly recommends at least 7 days, because long-running jobs may write files that are not yet committed, and a short window could delete them. A safety check blocks dangerous VACUUM commands. You can disable it by setting spark.databricks.delta.retentionDurationCheck.enabled to false, but only when you are sure no operation on the table runs longer than the interval you plan to use.
Checkpoint 2 of 6· Exam question
A compliance team asks the data engineering team to fully purge a customer's records from a production Delta table within days of an erasure request, rather than waiting out the default 30-day table history window. The team is considering lowering `delta.deletedFileRetentionDuration` and running `VACUUM` shortly after the `DELETE` completes. Which of the following are valid considerations the team should account for before doing this? (Select 3)(Select 3)
Correct answers: A, B, C — Shortening the retention duration and running `VACUUM` soon after the delete removes stale files sooner, but it also shortens the window available for time travel queries and concurrent long-running reads on the table.; A streaming job consuming this table via `readChangeFeed`, or one holding checkpointed offsets referencing now-removed files, can fail once `VACUUM` deletes the files those checkpoints still depend on.; Change data files are removed by `VACUUM` too, but pre-delete row values recorded in the transaction log persist until those log versions age past `delta.logRetentionDuration`, so both settings need lowering together.
- A. The retention duration controls how long removed files stay available for time travel and for readers that started before the delete. Lowering it to purge faster directly trades away that safety window, so any long-running query or rollback need has to be weighed against the erasure deadline.
- B. Structured Streaming sources and CDC consumers track progress against specific data files or log versions; if `VACUUM` removes files a checkpoint still references, the stream can fail with a file-not-found error. This is a real operational risk that must be checked before accelerating cleanup.
- C. Change data files follow the table's retention and get cleaned up by `VACUUM`, but the row values are also recorded in the transaction log itself, which is governed separately by `delta.logRetentionDuration`. A purge plan that only shortens file retention without also shortening log retention can leave historical values queryable through `table_changes()`.
- D. Table properties such as `delta.deletedFileRetentionDuration` are set per table and are not automatically inherited or propagated to materialized views built on top of it; each downstream object's own retention and refresh behavior must be configured and verified independently.
- E. Change data files are cleaned up by `VACUUM` following the table's file retention setting, but the row values are also captured in the transaction log, which is retained according to `delta.logRetentionDuration` independently of the `VACUUM` threshold. Lowering only the file retention setting can leave history queryable through the log.
- F. Predictive Optimization is a workspace/account-level feature that manages maintenance operations like `OPTIMIZE` and `VACUUM` for Unity Catalog managed tables; running a manual `VACUUM` with a custom retention value does not permanently disable it or require manual re-enabling afterward.
3.Deletion vectors: REORG TABLE ... APPLY (PURGE) before VACUUM
Deletion vectors speed up DELETE, UPDATE and MERGE. Instead of rewriting each Parquet file that holds an affected row, they mark the row as modified in metadata, and reads apply those marks at query time. On Delta Lake tables you have to enable deletion vectors explicitly. Apache Iceberg v3 tables have them by default.
This is a soft delete. Data modifications on tables with deletion vectors, and dropping columns with column mapping enabled, both leave the old values in the table's current files. Running VACUUM alone won't remove them, because those files are still referenced by the current version.
REORG TABLE events WHERE date >= '2022-01-01' APPLY (PURGE);APPLY (PURGE) rewrites only the files that contain soft-deleted data. The optional WHERE clause accepts only filters on partition key attributes. The command is idempotent, so running it a second time has no effect. It creates a new table version, but the pre-REORG files are still kept for time travel. That means you need a delay: VACUUM can delete those older files only after they pass the retention threshold. Shortening the retention period shortens the wait, at the cost of less history.
Checkpoint 3 of 6· Put it in order
Put the steps in order to physically erase a user from a Delta table that has deletion vectors enabled.
- 1.Delete the user's rows with DELETE or MERGE
- 2.Run VACUUM to delete the older files
- 3.Wait until the pre-REORG files are older than the VACUUM retention threshold
- 4.Run REORG TABLE ... APPLY (PURGE) to rewrite files containing soft-deleted rows
The DML only marks the rows as deleted. REORG rewrites the current files without them, and VACUUM removes the old files after they have expired.
“This means that the VACUUM must be done with a delay after the REORG to guarantee that the older files have expired.”Source: docs.databricks.com
Checkpoint 4 of 6· Fill the gap
Which REORG option rewrites files to remove soft-deleted rows?
REORG TABLE events APPLY ( ? );APPLY (PURGE) is the option whose purpose is purging soft-deleted data. CHECKPOINT and UPGRADE are for metadata management and for upgrading the Iceberg compatibility version.
Source: docs.databricks.com4.Copies that outlive VACUUM
VACUUM is the last step for files the table manages, but erased data can survive elsewhere. When disk caching is enabled, a cluster may still hold data from Parquet files that VACUUM has deleted, so old table versions could still be queried from that cluster until it restarts. Change data feed records are stored in the _change_data directory, and VACUUM removes them along with the rest. Table history is also not an archive. Databricks says not to use it as a long-term backup, so a compliant purge design shouldn't depend on old versions sticking around.
The cluster's disk cache still holds data from the Parquet files that VACUUM deleted. Restarting the cluster clears the cache.
Checkpoint 5 of 6· Check yourself
Which statement about VACUUM and change data feed is correct?
VACUUM skips most underscore directories, but the vacuum docs explicitly say change data feed data in _change_data is removed by VACUUM.
“Data for change data feed is managed in the _change_data directory and removed with VACUUM.”Source: docs.databricks.com
Checkpoint 6 of 6· Exam question
A Lakeflow Spark Declarative Pipeline ingests raw customer events into a bronze Delta table, and a downstream streaming table `silver_events` is defined to read incrementally from bronze. A GDPR erasure request requires removing one customer's rows from both layers. The bronze table has already been updated with a matching `DELETE FROM` statement, but the pipeline run for `silver_events` now fails because the stream reading from bronze encounters a non-append change it cannot process. What is the correct way to complete the deletion in `silver_events` without permanently breaking the pipeline?
Correct answer: A — Delete the same matching rows directly from `silver_events`, then add the `skipChangeCommits` option to the stream reading from bronze so future non-append changes are skipped instead of failing.
- A. Streaming tables process their source as an append-only feed, so a delete upstream has to be applied separately and directly on the streaming table itself. Adding `skipChangeCommits` tells the stream reading from bronze to skip over non-append operations going forward instead of erroring out, which is the documented pattern for keeping the pipeline running after a manual downstream delete.
- B. A full reprocess is unnecessary and expensive; streaming tables can continue operating on new appended data as long as the stream is configured to skip the non-append change that caused the failure, rather than requiring the entire table to be rebuilt from scratch.
- C. `ignoreChanges` prevents the stream from failing on non-append operations, but it does so by re-emitting affected records rather than deleting them, and it does not remove or retroactively alter rows already written to the downstream table. Relying on it alone leaves the deleted customer's rows present in `silver_events`.
- D. Materialized views can incrementally handle source deletes, but converting the entire object and dropping the streaming table is a disproportionate response to a single erasure request and is not the documented remediation; the deletion can be completed on the existing streaming table with a direct delete plus `skipChangeCommits`.
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Once a DELETE commits, the customer's data is gone from storage.Why is that wrong?
The DELETE creates a new version, but the earlier data files stay in cloud storage and can be reached with time travel until VACUUM removes them.
Covered in Why a DELETE is not yet an erasure
2.VACUUM keeps deleted data files for 30 days by default.Why is that wrong?
The VACUUM threshold (deletedFileRetentionDuration) defaults to 7 days. The 30-day default is logRetentionDuration, which governs table history.
Covered in VACUUM and predictive optimization on Unity Catalog managed tables
3.On a table with deletion vectors, DELETE followed by VACUUM physically erases the rows.Why is that wrong?
Deletion vectors only mark rows as deleted in metadata, so the data stays in the current files. You must run REORG TABLE ... APPLY (PURGE), then VACUUM once the old files expire.
Covered in Deletion vectors: REORG TABLE ... APPLY (PURGE) before VACUUM
Practise it for real
Erase one user from a Delta table with deletion vectors and confirm the files are physically purged.
1.Run spark.sql("DELETE FROM bronze.users WHERE user_id = 5") against a test copy of the table.
Why: This removes the user from the current table version.
You should see: A new table version in which user 5 no longer appears.
2.Run DESCRIBE HISTORY on the table, then query an earlier version with VERSION AS OF.
Why: This shows that the deleted rows can still be reached through time travel.
You should see: The DELETE appears in the history, and the earlier version still returns user 5.
3.Run REORG TABLE on the table with APPLY (PURGE).
Why: With deletion vectors the delete was soft, and REORG rewrites the current files without the deleted rows.
You should see: A new version in the history. Older versions still reference the old files.
4.Once the retention threshold has passed, run VACUUM with DRY RUN, then run VACUUM.
Why: DRY RUN lets you check the list of files before the permanent deletion.
You should see: DRY RUN lists the expired files. After VACUUM, time travel to versions older than the retention period fails.
Stuck? Get a nudge
If VACUUM deletes nothing, the old files probably haven't passed delta.deletedFileRetentionDuration yet. Files expire based on when they were logically removed, not on their storage timestamps.
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/tables/historyOfficial docs
“Table history retention is determined by the table setting logRetentionDuration, which is 30 days by default.”
↩︎ Why a DELETE is not yet an erasure“Don't use table history as a long-term backup solution for data archival.”
↩︎ Copies that outlive VACUUM - 2.https://docs.databricks.com/aws/en/ldp/gdprOfficial docs
“By default, Delta Lake retains table history, including deleted records, for 30 days, and makes it available for time travel and rollbacks.”
↩︎ Why a DELETE is not yet an erasure“For tables without predictive optimization enabled, Lakeflow pipelines automatically perform maintenance tasks within 24 hours of streaming tables and materialized views being updated.”
↩︎ VACUUM and predictive optimization on Unity Catalog managed tables“For tables with deletion vectors enabled, after deleting records, you must also run REORG TABLE ... APPLY (PURGE) to permanently delete underlying records.”
↩︎ Exam trap 3 - 3.
“Predictive optimization automatically runs VACUUM on Unity Catalog managed tables.”
↩︎ VACUUM and predictive optimization on Unity Catalog managed tables“it is still present in the older files that are used for time travel”
↩︎ Deletion vectors: REORG TABLE ... APPLY (PURGE) before VACUUM“Restarting the cluster will remove the cached data.”
↩︎ Copies that outlive VACUUM“Data files removed by VACUUM might contain records that have been modified or deleted.”
↩︎ Exam trap 1“The default retention threshold for data files after running VACUUM is 7 days.”
↩︎ Exam trap 2“Log files are deleted automatically and asynchronously after checkpoint operations and are not governed by VACUUM.”
↩︎ Checkpoint“This means that the VACUUM must be done with a delay after the REORG to guarantee that the older files have expired.”
↩︎ Checkpoint“Data for change data feed is managed in the _change_data directory and removed with VACUUM.”
↩︎ Checkpoint - 4.
“Delta table data files are deleted according to the time they have been logically removed from Delta's transaction log plus retention hours”
↩︎ VACUUM and predictive optimization on Unity Catalog managed tables“Databricks strongly recommends setting a retention interval of at least 7 days.”
↩︎ VACUUM and predictive optimization on Unity Catalog managed tables - 5.
“For Delta Lake tables, you must explicitly enable deletion vectors.”
↩︎ Deletion vectors: REORG TABLE ... APPLY (PURGE) before VACUUM - 6.
“APPLY (PURGE) only rewrites files that contain soft-deleted data.”
↩︎ Deletion vectors: REORG TABLE ... APPLY (PURGE) before VACUUM