CertSafari
    Databricks Certified Data Engineer Professional - October 9 onwards· Lessons

    Domain 6 · Lesson 37/45

    GDPR right-to-erasure in Delta Lake: delete, purge, vacuum and propagate

    Implement a data purging strategy that satisfies data retention and deletion policies (e.g., GDPR right-to-erasure, GDPR right-to-be-forgotten deletion) using Delta Lake and Unity Catalog features.

    20 min read
    1.6% of exam
    8 sources
    Published 22 Oct 2026
    Docs as of 1 Oct 2026

    What you will be able to do

    • Design a right-to-be-forgotten workflow that deletes from bronze first, driven by a control table of deletion requests
    • Explain why DELETE alone leaves a subject's data in time travel, and use VACUUM with delta.deletedFileRetentionDuration and delta.logRetentionDuration to remove it
    • Use REORG TABLE … APPLY (PURGE) before VACUUM on tables with deletion vectors
    • Keep downstream materialized views and streaming tables correct and running after source deletes, using skipChangeCommits or a full refresh
    • Apply auto time-to-live to enforce time-based retention on Unity Catalog managed tables

    Key concept

    Logical delete vs physical purge — A DELETE removes a subject's rows from the current version of a Delta table, but their bytes stay in storage: in old data files kept for time travel, and on deletion-vector tables, in the current files too. Erasure is only complete once those files have been rewritten (REORG … APPLY (PURGE)) and removed (VACUUM).

    1.Erasure requests start with a control table and the bronze layer

    GDPR and CCPA give a customer the right to have all of their personally identifiable information permanently deleted, and the clock starts when they ask. The request has to be completed within a fixed period, typically one calendar month. That deadline is why erasure is a scheduled process, not a one-off query someone remembers to run.

    The recommended starting point is the bronze layer. A scheduled job reads a table of deletion requests, deletes the matching subjects from bronze, and then the change is carried forward into silver and gold. Starting at bronze matters because every downstream table is derived from it: a subject removed from gold but still present in bronze would come back on the next rebuild.

    Two commands do the deleting. A single subject can be removed with a plain DELETE FROM bronze.users WHERE user_id = 5. For a batch of requests, MERGE is the recommended form: it joins the target table to the control table on user_id and deletes every match in one transaction. Once the MERGE succeeds, the job marks those requests as processed in the control table, which gives the compliance team a record of what was done.

    Deleting every subject listed in the GDPR control table with one MERGEpython
    spark.sql("""
      MERGE INTO target
      USING (
        SELECT user_id
        FROM gdpr_control_table
      ) AS source
      ON target.user_id = source.user_id
      WHEN MATCHED THEN DELETE
    """)

    Table design decides how much has to be deleted. When user records are keyed on a surrogate such as user_id rather than a natural key such as email, the PII can be deleted and the non-PII behavioural data can stay. Obfuscation through pseudonymization or masking is the alternative to deletion, but complete erasure is the safest choice, because it is often the only way to remove the risk of re-identification.

    The scope reaches beyond Delta Lake. Kafka topics, landing files in cloud storage and source databases hold the same PII, and the request covers them too. Deleting bronze while the raw files sit in a landing bucket only satisfies part of the request.

    Checkpoint 1 of 9· Fill the gap

    A scheduled job uses the GDPR control table to erase every subject who asked to be forgotten. Which keyword completes the MERGE so that only those subjects' rows are deleted?

    spark.sql("""
      MERGE INTO target
      USING (
        SELECT user_id
        FROM gdpr_control_table
      ) AS source
      ON target.user_id = source.user_id
      WHEN  ?  THEN DELETE
    """)

    Checkpoint 2 of 9· Check yourself

    A team must meet GDPR right-to-erasure requests across a bronze → silver → gold lakehouse. Which approach is recommended?

    Sources1

    2.DELETE keeps history; VACUUM and retention settings remove it

    A Delta DELETE is a new commit, not an erasure. The data files that held the subject's rows are dropped from the current version, but they stay in cloud storage so earlier versions can still be queried and restored. Reading an old version needs two things: the log entries for that version and the data files they point to. Two separate retention settings control those two things, and erasure only works if you understand both.

    The two retention properties that decide how long deleted data survives
    PropertyDefaultWhat it governsWho removes the expired items
    delta.deletedFileRetentionDuration7 daysHow long data files that are no longer referenced are kept before VACUUM may delete themVACUUM (manual, or run by predictive optimization)
    delta.logRetentionDuration30 daysHow long table history (transaction log entries) is kept for time travelAutomatic cleanup after checkpoints are written; not VACUUM

    VACUUM is the command that physically deletes the files. It removes data files that are no longer referenced by the latest table state and that were logically removed longer ago than delta.deletedFileRetentionDuration. The clock starts when the file was removed from the transaction log, not at the file's modification time. Once VACUUM has run, versions older than the retention window can no longer be queried. On Unity Catalog managed tables with predictive optimization, VACUUM runs automatically. Streaming tables and materialized views in Lakeflow pipelines get their maintenance from the pipeline, either through predictive optimization or within 24 hours of an update. Tables with neither need a scheduled VACUUM table_name. Running VACUUM table_name DRY RUN first lists the files it would remove.

    Setting the file-retention window that VACUUM uses on a tablesql
    ALTER TABLE table_name SET TBLPROPERTIES ('delta.deletedFileRetentionDuration' = '30 days');

    The log is the other half. Log files are cleaned up automatically and asynchronously after checkpoints, outside VACUUM's control, and they keep 30 days of history by default. To make a subject's history disappear sooner, both windows have to shrink. Lowering only the file retention leaves the history entries in place for as long as delta.logRetentionDuration allows. In Databricks Runtime 18.0 and above, logRetentionDuration must be greater than or equal to deletedFileRetentionDuration, so the two are adjusted together. These are per-table properties. Changing them on bronze does not change any table built from it.

    The change feed is purged by the same command. Change data feed files live in the table's _change_data directory, and VACUUM removes them along with other expired files. Propagating deletes through the change feed is covered below. Here the point is the opposite one: once VACUUM has run, the change records for older versions are gone, just like the time-travel versions.

    A shorter window has a cost. Anything that still needs an old version loses it: a time-travel query, a rollback, or a long-running reader working through versions VACUUM has already cleaned up. Databricks strongly recommends a retention interval of at least 7 days, because jobs that run for days can write files that are not committed yet, and a short window lets VACUUM delete them before the job finishes. Delta enforces this with a safety check. You can only bypass it by setting spark.databricks.delta.retentionDurationCheck.enabled to false, and only when no operation on the table runs longer than the interval you choose.

    Checkpoint 3 of 9· Check yourself

    To shorten how long an erased customer's history survives, an engineer lowers delta.deletedFileRetentionDuration on bronze.users. Once that window has passed, they run VACUUM. Which statement is still true afterward?

    Checkpoint 4 of 9· 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)

    0 of 3 selected

    Sources12345

    3.Deletion vectors need REORG … APPLY (PURGE) before VACUUM

    Deletion vectors speed up DELETE, UPDATE and MERGE by marking rows as removed in metadata instead of rewriting the Parquet file. For erasure, that speed has a catch. After the DELETE, the subject's row is hidden from queries, but its bytes are still inside a data file that the current table version references.

    VACUUM never rewrites a file. It only deletes files that the latest table state no longer references. A soft-deleted row sits in a file that the current version still uses, so no retention setting, not even zero hours, lets VACUUM touch it. Running the same DELETE again doesn't help either, because the row is already marked as deleted. The fix is a separate rewrite step, and the order of the steps matters.

    Fully purging a soft-deleted row takes three steps:

    1. Run DELETE (or MERGE … WHEN MATCHED THEN DELETE). The row is marked in a deletion vector.
    2. Run REORG TABLE user_profiles APPLY (PURGE). Files that contain soft-deleted data are rewritten without those rows, and the result is committed as a new table version. The old files are still kept for time travel.
    3. Run VACUUM once those old files have passed the retention window. Only then are the pre-REORG files deleted from storage.
    Purging soft-deleted rows, for the whole table or only matching partitionssql
    > REORG TABLE events APPLY (PURGE);
    
    > REORG TABLE events WHERE date >= '2022-01-01' APPLY (PURGE);

    APPLY (PURGE) only rewrites files that contain soft-deleted data, and it is idempotent: a second run on the same data does nothing. Its optional WHERE clause accepts only partition-column predicates. On large tables, the default spark.databricks.delta.reorg.purgeMode of all scans every Parquet footer for both dropped-column data and soft-deleted rows. Setting it to rows limits the scan to files with soft-deleted rows, which can be faster when the table has no dropped columns. The same requirement applies to materialized views and streaming tables that have deletion vectors enabled.

    Checkpoint 5 of 9· Put it in order

    Customer U123 has asked to be erased from user_profiles, a table with deletion vectors enabled. Put the steps in the order that physically removes their data from storage.

    1. 1.Run DELETE FROM user_profiles WHERE user_id = 'U123', which marks the row in a deletion vector
    2. 2.Wait until the pre-REORG files have passed the delta.deletedFileRetentionDuration window
    3. 3.Run VACUUM to delete the pre-REORG files from cloud storage
    4. 4.Run REORG TABLE user_profiles APPLY (PURGE) so the files holding soft-deleted rows are rewritten without them

    Checkpoint 6 of 9· Exam question

    A Unity Catalog managed Delta table user_profiles has deletion vectors enabled. To satisfy a GDPR right-to-erasure request, an engineer runs: DELETE FROM user_profiles WHERE user_id = 'U123' A subsequent privacy audit finds that the physical row data for U123 is still present in the underlying Parquet files. What should the team do to permanently remove those physical records?

    Sources14367

    4.Propagating deletes to materialized views and streaming tables

    After bronze, the delete has to reach silver and gold, and the two kinds of downstream pipeline table behave very differently. Materialized views handle it themselves. A materialized view always returns the correct result. It computes incrementally when that is cheaper, but never at the cost of correctness, so a source delete may simply trigger a full recompute. It still has to be refreshed, and maintenance has to run, before the deleted data is fully processed.

    Streaming tables break instead. A streaming read from a Delta table expects append-only data. An update or delete in the source is not supported and breaks the stream, so the run that follows a GDPR delete on bronze fails. Two remedies exist, and they suit different situations.

    Two ways to finish an erasure through a streaming table
    ApproachStepsWhen it winsRisk
    skipChangeCommits1) DELETE from the source Delta table; 2) DELETE the same rows from the streaming table with DML; 3) add skipChangeCommits to the streaming readDefault choice; works when upstream history has expired or is expensive to reprocessNone to the stream, but you must delete downstream rows yourself
    Full refresh1) DELETE from the source; 2) fully refresh the streaming table, which clears streaming state and reprocesses all dataHistorical data is still available and reprocessing it is cheapData that has aged out upstream, such as a Kafka topic with 7-day retention, is not reprocessed, so it is lost

    skipChangeCommits tells the stream to ignore every commit that is not an insert, such as updates and deletes. It does not reach back and remove rows the stream has already written, which is why step 2 deletes the subject from the streaming table explicitly. Without that step, the stream keeps running and the PII stays in silver.

    A Lakeflow pipelines streaming table that skips update and delete commits on its sourcesql
    CREATE OR REFRESH STREAMING TABLE my_table AS
    SELECT * FROM STREAM(source_table) OPTIONS (skipChangeCommits);

    A sturdier design reads the source's Change Data Feed (CDF) instead of its append stream. The delete rows then arrive as events, and the processing code applies them downstream. A tool that skips deletes can't do that.

    Checkpoint 7 of 9· Fill the gap

    After a GDPR DELETE on its bronze source, the silver streaming table fails on its next run. The engineer has already deleted the subject's rows from silver with DML. Which option on the streaming read lets the pipeline keep running past the delete commit?

    CREATE OR REFRESH STREAMING TABLE my_table AS
    SELECT * FROM STREAM(source_table) OPTIONS ( ? );

    Checkpoint 8 of 9· 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?

    Sources1

    5.Time-based retention with auto time-to-live

    Some retention rules are about age, not individual requests: 'keep events for one year', or 'erase an account 20 days after the deletion request is approved'. Auto time-to-live (auto-TTL) enforces rules like these on Unity Catalog managed tables. You give it a timestamp column and an expiration period in days. Databricks then runs the DELETE, the PURGE and the VACUUM in the background, which covers the same three steps as the manual workflow.

    Expiring rows 30 days after their created_at timestampsql
    ALTER TABLE my_catalog.my_schema.my_table DELETE ROWS 30 DAYS AFTER created_at;

    The time column can be DATE, TIMESTAMP or TIMESTAMP_NTZ, including a nested field such as payload.ts. Auto-TTL works on managed Delta tables, Iceberg tables and streaming tables in Lakeflow pipelines. On a streaming table, the policy goes in the pipeline definition (DELETE ROWS … DAYS AFTER in SQL, or the auto_ttl argument in Python) because SQL ALTER is not supported there. Setting a policy requires MODIFY on the table and Databricks Runtime 17.3 or above. It also depends on predictive optimization: turning that off stops auto-TTL from running.

    Auto-TTL does not delete on a precise schedule. The gap between a row expiring and its permanent removal can be up to 6 days plus the data-retention property, which defaults to 7 days. Exact timing also varies with system load. Size the expiration period so that this buffer still lands inside your compliance deadline, and check what actually happened with DESCRIBE HISTORY or the predictive optimization system table.

    Checkpoint 9 of 9· Check yourself

    Bronze.events, a Unity Catalog managed table, now has the policy DELETE ROWS 365 DAYS AFTER created_at. A Structured Streaming job reads bronze.events into silver. What happens to that job when auto-TTL first removes expired rows?

    Sources8

    Practise it for real

    Erase one subject from a deletion-vector Delta table so that no copy of their rows remains in the current files or in storage kept for time travel.

    1. 1.Run DELETE FROM bronze.users WHERE user_id = 5 (or a MERGE … WHEN MATCHED THEN DELETE against your control table).

      Why: Removes the subject from the current table version.

      You should see: A new table version; on a deletion-vector table the rows are only marked as deleted.

    2. 2.Run REORG TABLE bronze.users APPLY (PURGE).

      Why: Rewrites the files that contain soft-deleted rows so the current files no longer hold the subject's data.

      You should see: Another new table version; the pre-REORG files are still kept for time travel.

    3. 3.After the retention window has passed, run VACUUM bronze.users DRY RUN.

      Why: Previews which unreferenced files VACUUM will delete before anything is removed.

      You should see: A list of up to 1000 files, including the files rewritten by the DELETE and the REORG.

    4. 4.Run VACUUM bronze.users.

      Why: Physically deletes the expired files from cloud storage.

      You should see: Time travel to versions before the retention window no longer works.

    Stuck? Get a nudge

    If DRY RUN lists none of the files you expected, check whether the REORG commit is younger than delta.deletedFileRetentionDuration.

    Sources

    (8)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “deletion requests must be executed during a specified period (for example, within one calendar month).”
      ↩︎ Erasure requests start with a control table and the bronze layer
      “deleting data in the bronze layer first, driven by a scheduled job that queries a table of deletion requests”
      ↩︎ Erasure requests start with a control table and the bronze layer
      “When deleting a large number of records together at one time, we recommend using the MERGE command.”
      ↩︎ Erasure requests start with a control table and the bronze layer
      “if you are using a non-natural key such as user_id instead of a natural key like email, you can delete PII data”
      ↩︎ Erasure requests start with a control table and the bronze layer
      “you must also remember to delete data in upstream sources, such as queues and cloud storage.”
      ↩︎ Erasure requests start with a control table and the bronze layer
      “By default, Delta Lake retains table history, including deleted records, for 30 days, and makes it available for time travel and rollbacks.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “Lakeflow pipelines automatically perform maintenance tasks within 24 hours of streaming tables and materialized views being updated.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “For tables with deletion vectors enabled, after deleting records, you must also run REORG TABLE ... APPLY (PURGE) to permanently delete underlying records.”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
      “You must refresh a materialized view and run maintenance to ensure that deletions are completely processed.”
      ↩︎ Propagating deletes to materialized views and streaming tables
      “deleting data from a source could cause a materialized view to fully recompute.”
      ↩︎ Propagating deletes to materialized views and streaming tables
      “Any other operation, such as updating or deleting a record from a streaming source, is not supported and breaks the stream.”
      ↩︎ Propagating deletes to materialized views and streaming tables
      “This flag indicates that the streaming table should skip anything other than inserts, such as updates or deletes.”
      ↩︎ Propagating deletes to materialized views and streaming tables
      “won't be processed again, which could cause data loss.”
      ↩︎ Propagating deletes to materialized views and streaming tables
      “stream from the change feeds of Delta tables instead, and handle updates and deletes in your processing code.”
      ↩︎ Propagating deletes to materialized views and streaming tables
      “removes data files that are no longer referenced by a Delta table and are older than a specified retention threshold, permanently deleting the data.”
      ↩︎ Key concept
      “This flag indicates that the streaming table should skip anything other than inserts, such as updates or deletes.”
      ↩︎ Exam trap 3
      “We recommend this option for streaming tables only in the scenario where historical data is available and processing it again won't be costly.”
      ↩︎ Exam trap 4
      “start GDPR and CCPA compliance by deleting data in the bronze layer first, driven by a scheduled job that queries a table of deletion requests”
      ↩︎ Checkpoint
    2. 2.
      “To time travel to a previous version, you must retain both the log and the data files for that version.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
    3. 3.
      “The default retention threshold for data files after running VACUUM is 7 days.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “The ability to query table versions older than the retention period is lost after running VACUUM.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “Predictive optimization automatically runs VACUUM on Unity Catalog managed tables.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “Log files are deleted automatically and asynchronously after checkpoint operations and are not governed by VACUUM.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “Data for change data feed is managed in the _change_data directory and removed with VACUUM.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “it may be possible to query the data of previous table versions whose files have been deleted.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “This means that the VACUUM must be done with a delay after the REORG to guarantee that the older files have expired.”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
      “Log files are deleted automatically and asynchronously after checkpoint operations and are not governed by VACUUM.”
      ↩︎ Exam trap 2
    4. 4.
      “Delta table data files are deleted according to the time they have been logically removed from Delta's transaction log plus retention hours”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “If your retention period is too short, VACUUM could delete these uncommitted files before the job completes.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “Databricks strongly recommends setting a retention interval of at least 7 days.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “data files that are no longer in the latest state of the transaction log for the table and are older than a retention threshold”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
    5. 5.
      “controls how long the history for a table is kept. The default is interval 30 days.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
      “In Databricks Runtime 18.0 and above, logRetentionDuration must be greater than or equal to deletedFileRetentionDuration.”
      ↩︎ DELETE keeps history; VACUUM and retention settings remove it
    6. 6.
      “APPLY (PURGE) only rewrites files that contain soft-deleted data.”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
      “REORG TABLE is idempotent, meaning that if it is run twice on the same dataset, the second run has no effect.”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
      “After running APPLY (PURGE), the soft-deleted data may still exist in the old files. You can run VACUUM to physically delete the old files.”
      ↩︎ Exam trap 1
    7. 7.
      “The rows value limits the operation to handle only files with soft-deleted rows.”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
      “deletion vectors don't apply to future writes to the view or table, but existing deletion vectors remain.”
      ↩︎ Deletion vectors need REORG … APPLY (PURGE) before VACUUM
    8. 8.
      “Databricks runs DELETE, PURGE, and VACUUM operations in the background to remove expired rows and clear them from storage.”
      ↩︎ Time-based retention with auto time-to-live
      “Expire rows 20 days after a delete request is processed by specifying a 20 day expiration period on a custom del_request_approved timestamp column.”
      ↩︎ Time-based retention with auto time-to-live
      “Altering a streaming table to use auto time-to-live using SQL is not supported.”
      ↩︎ Time-based retention with auto time-to-live
      “You must have MODIFY permissions on a table to set or delete an auto time-to-live policy.”
      ↩︎ Time-based retention with auto time-to-live
      “Turning off predictive optimization on a table with auto time-to-live enabled prevents auto time-to-live from running.”
      ↩︎ Time-based retention with auto time-to-live
      “The buffer time between row expiration and permanent deletion can be up to 6 days plus the value of the data retention table property”
      ↩︎ Time-based retention with auto time-to-live
      “Without this setting, the streaming read fails when auto time-to-live deletes rows.”
      ↩︎ Time-based retention with auto time-to-live
      “Auto time-to-live deletion operations appear as data changes. Without this setting, the streaming read fails when auto time-to-live deletes rows.”
      ↩︎ Checkpoint

    Spotted a mistake, or was something unclear? Tell us.