Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a breaking point when a database transaction will get corrupted?

I'm interested in how database transactions "commonly" are implemented in a database system, like for instance MySQL.

Assuming the actual writing of data to the physical database storage isn't an atomic operation (speaking in terms of clockcycles now), shouldn't I be able to corrupt a transaction by for instance ripping the power cable at some carefully chosen moment?

like image 602
sharkin Avatar asked Jan 24 '23 03:01

sharkin


2 Answers

If the database system is carefully written, there should be no point in time where power outage can corrupt data, and when power outage occurs, no committed data should ever be lost.

The rdbms writes data first to a transaction log before actually updating the data. After a crash, it replays the log, copying any pending changes from the log into the database, and rolling back any transactions which have not been completed in the log. Commit is reported as successful only after the hard disk has reported a completed write operation to the log.

like image 117
Martin v. Löwis Avatar answered Jan 25 '23 17:01

Martin v. Löwis


Databases follow the ACID properties. No matter when something explodes, there's a way to at the very least roll-back to a known correct state.

like image 39
Ben S Avatar answered Jan 25 '23 16:01

Ben S