Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Databases

What really happens when you delete a file or a database row?

You hit delete and the file is gone. Except it is not. Here is what really happens on disks, SSDs and databases, and why GDPR erasure is hard.

Derpx0610 Nov · 4 min read
Contents
What does the file system do when you delete?What does an SSD add?Why doesn't a database remove the row right away?What is a tombstone?Why the wait? The zombie problemWhat does "right to erasure" mean with all this?What I'd do differentlySources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
What does the file system do when you delete?What does an SSD add?Why doesn't a database remove the row right away?What is a tombstone?Why the wait? The zombie problemWhat does "right to erasure" mean with all this?What I'd do differentlySources

You hit delete on a 2 GB movie and your phone storage bar barely moves. Or it moves, but the file is "still in the bin". Either way, did the file actually leave?

Short answer: mostly no. Delete usually means "stop pointing at this", not "destroy this". Let's follow one deleted file down the stack and see where it goes.

What does the file system do when you delete?

A file system keeps a list of names and where each file's data lives. Think of a library catalogue card. Throw the card away and the book is still on the shelf, just nobody knows where.

The Linux manual describes unlink() as something that "deletes a name from the filesystem". If that was the last name and nobody has the file open, the space is "made available for reuse". Available for reuse, not wiped.

Before deleteName points to the data blocks.
→
After deleteName is gone. Blocks wait to be overwritten.
The bytes stay until something else is written over them.

If some program still has the file open, even the space stays taken until it closes. That's why a disk can look full after you delete a big file. A program is still using it.

Why this matters: the file system only forgets. But phones and laptops use SSDs. Do they behave differently?

What does an SSD add?

An SSD (the flash storage in most phones and laptops) can't just overwrite old data in place the way you'd erase a pencil mark. So the file system can send it a message called TRIM, which means "these blocks aren't used anymore, you can clean them up".

Two things are worth knowing. The ext4 docs say its discard option, which sends TRIM when blocks are freed, is off by default (nodiscard). And the fstrim manual states that it discards unused blocks across a file system, mainly for SSDs, but also notes that not all blocks will be discarded in some cases.

I'm not claiming the data is always recoverable. I'm saying "gone" depends on settings and the drive, and delete alone doesn't promise it.

So disks forget lazily. Databases are even stranger.

Why doesn't a database remove the row right away?

In PostgreSQL, the docs say an UPDATE or DELETE "does not immediately remove the old version of the row". The old version stays because other running queries might still need to see it.

A cleaner called VACUUM comes later. The standard version "removes dead row versions in tables and indexes and marks the space available for future reuse", but it does not normally give the space back to the operating system.

Click Next and follow one DELETE through PostgreSQL. Notice that the row is still around after step 2.

You
Table
Older query
VACUUM

You run DELETE on a row

Step 1 of 4
Simplified from the PostgreSQL docs. Only a table rewrite, like VACUUM FULL, shrinks the file.

So what: even in a database, DELETE starts a cleanup instead of finishing it. And some databases take that idea further.

What is a tombstone?

Some databases (Cassandra, RocksDB) never edit old files at all. They write new ones. So a delete is just a new record that marks the key as dead. That record is called a tombstone.

Cassandra's docs say it handles a deletion as an insert of a time-stamped marker. By default it keeps tombstones for gc_grace_seconds, which is 864000 seconds (ten days). The real data goes away only when a compaction (merging files and throwing out old stuff) happens after that.

Notebook version

Imagine a notebook where you may never erase. To remove an item, you write a new line: "item removed". The old line stays until the notebook is copied out clean. A tombstone works like that new line.

RocksDB's docs say the same: deleting keys one at a time leaves tombstones, space isn't freed until compaction, and a pile of tombstones can slow down reads.

Ten days feels like a long wait. Is Cassandra just lazy?

Why the wait? The zombie problem

Cassandra keeps the tombstone on purpose. The docs warn that if a machine is down longer than gc_grace_seconds, its deleted data can be repaired back onto the others and reappear as a zombie.

Delete
Tombstone written
Grace period
Compaction removes it
↺ repeat
Delete in Cassandra is a process, not an event.

So the delay isn't laziness. It's how the system makes sure the delete reaches every copy. Now put all of this together with the law.

What does "right to erasure" mean with all this?

The GDPR (the EU's data protection law) has Article 17, the "right to erasure". It requires the controller to erase personal data "without undue delay" when one of the listed grounds applies.

Now picture what that means with everything above. One person's data may sit in a main database, replicas, tombstones waiting for compaction, backups, logs and SSD blocks. "Delete the row" touches only the first.

What teams can do

Know every place the data lives, delete in all of them, and write down how long each cleanup takes.

What stays hard

Backups and old files get cleaned only by their own schedules, so "gone" can take a while.

I'm not a lawyer, so I won't say what the law counts as erased. I only know the engineering side: it isn't one command.

What I'd do differently

I used to think DELETE was a verb with one meaning. Now I treat it as "start the cleanup". For private stuff, I'd ask where else the data is, and how long until each place actually forgets.

Key takeaways
  • Delete usually removes the pointer, not the data.
  • SSDs need a TRIM message, and ext4 has it off by default.
  • Databases keep dead rows or tombstones until VACUUM or compaction cleans up.
  • Real erasure means finding every copy, which is why GDPR-style requests are hard.

Sources

  • PostgreSQL docs: Routine Vacuuming
  • Apache Cassandra docs: Compaction overview
  • RocksDB wiki: Delete A Range Of Keys
  • Linux kernel docs: ext4
  • Linux man page: unlink(2)
  • Linux man page: fstrim(8)
  • GDPR Article 17
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Databases · 5 minWhat is a Bloom filter? A tiny "definitely not" checkerDatabases · 4 minB-Trees vs LSM-Trees: how databases store your dataDatabases · 5 minHow does a database keep your data when the power goes off?
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)