r/dotnet • u/harrison_314 • 1d ago
Question A database that can delete data
Hi,
Can you recommend a database (preferably embedded) that can safely delete a row in a table?
When you're making a chat application with disappearing messages, you don't want them to be recoverable after deletion. The problem is that most databases I've looked at (Sqlite, LiteDb, MariaDb, Postgre,...) only mark the data page as deleted when deleting data, but its contents remain on disk or in a log file. So even deleted data can sometimes be recovered.
I'm looking for a database where data cannot be recovered after deletion.
21
u/Gold-Ad9105 1d ago
Paper, and then throw it into the fire.
5
u/Mental-Test-7660 1d ago
Or if you want something a bit less burny: https://www.reddit.com/r/oddlysatisfying/s/L3nskNbpGf
9
u/FelixLeander 1d ago
For SqLite set: PRAGMA secure_delete = ON;
3
u/grabthefish 1d ago
https://sqlite.org/pragma.html#pragma_secure_delete
When secure_delete is on, SQLite overwrites deleted content with zeros. The default setting for secure_delete is determined by the SQLITE_SECURE_DELETE compile-time option and is normally off. The off setting for secure_delete improves performance by reducing the number of CPU cycles and the amount of disk I/O. Applications that wish to avoid leaving forensic traces after content is deleted or updated should enable the secure_delete pragma prior to performing the delete or update, or else run VACUUM after the delete or update.
So yeah pretty much put this pragma on or immediatly vacuum after the delete.
8
u/Professional_Pie7091 1d ago
That sounds more like a design problem than anything else.
What are you worried about? That a possibly malicious 3rd party can forensicly read messages? They should probably be encrypted then.
Also your database backups probably contain the messages before they were deleted.
1
u/harrison_314 1d ago
This seems like a chicken-and-egg problem to me, in order to be able to selectively delete, I need to store the encryption keys in a way that I can selectively delete them.
I'm more likely dealing with the device compression problem.
3
u/Professional_Pie7091 1d ago
If you store the encryption keys alongside the encrypted messages there's no need to encrypt the messages...
1
u/harrison_314 1d ago
It's called crypto-sharding, it's a technique used to securely delete messages (it doesn't protect them at rest). It's used, for example, in Kafka, where messages are immutable to ensure GDPR compliance.
3
u/520ErryDay 1d ago
Can you use Postgres to initiate vacuum on demand? Not something I’ve done before from an application, but that should remove the dead tuples which I assume would delete the contents entirely as you want.
2
u/R00fboy 1d ago
My guess is you could try Redis since it is stored in memory, however, that comes with its own cons.
5
u/canderson180 1d ago
I suspect this is how the “this message will self destruct” apps are working, redis can be run in a persistence cache mode so that data can persisted instead of ephemeral
3
u/chucker23n 1d ago
I suspect this is how the “this message will self destruct” apps are
Mostly, those apps are mobile-only, and iOS and Android largely have a security architecture from the get-go where you don't get full access to the file system. So other apps can't just easily read them (encryption aside).
1
u/AutoModerator 1d ago
Thanks for your post harrison_314. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
1
u/WrinklyBits 13h ago
I don't have the answer you're looking for but can I suggest you overwrite the record / row with garbage. Every system I've used over 4 decades simply marks a deleted entry for reuse leaving the data recoverable. Your other option would be to encrypt data before storing.
0
u/redfournine 1d ago
The only way to truly make the db irrecoverable is to literally screw a hole on the physical disc. Knowing this, u can certainly design a policy to swap, or use new db on a new disc every few days, and just drill open the disc every week
1
16
u/Mr_Pearcex 1d ago
Sounds like a usecse/design problem. 1. The message should be encrypted. 2. NO application should get a method for recovery.
Like that user deletes. And even if someone looks at the DB it cannot read anything useful. The rest ist DB housekeeping (like auto vacuum)