Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite3 with python: where is data stored before commit?

I saw a question similar to mine, but for SQL databases in general. It said that when you insert data but before the commit, only the commands are saved and they are saved in RAM. Only after the commit will the RAM be emptied and the data be in the database.

However, I think I was noticing different behavior using sqlite3 with Python. I left my commit at the very end of the script. My program ran out of space and aborted partway, but it wasn't because of the RAM being full. It said that the disk space was full, which I confirmed was indeed full on my computer, a substantial part being taken up by my database file.

I know I need more disk space to create this database, which won't be a problem, but I was wondering, at least specifically with sqlite3 and Python (if the particular case matters), what is actually happening with my data/commands before the commit? In other words, where and how are they getting stored? Is it different for different databases? Should I ever be worried about using up all my RAM when working with databases by not committing until the end?

like image 261
dcripplinger Avatar asked Aug 29 '13 15:08

dcripplinger


People also ask

Where is data stored before commit?

All instructions before commit come under a partially committed state and are stored in RAM.

Where is SQLite database stored Python?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.

Does sqlite3 automatically commit?

By default, SQLite operates in auto-commit mode. It means that for each command, SQLite starts, processes, and commits the transaction automatically. To start a transaction explicitly, you use the following steps: First, open a transaction by issuing the BEGIN TRANSACTION command.


1 Answers

SQLite copies unmodified pages of data in a temporary rollback journal file, and applies your changes to in memory copies of those same pages. When you make enough changes so that memory becomes a problem, changes are flushed out to the original database. The rollback journal is used to roll back incomplete transactions.

How different databases handle the rollback journal depends heavily on the database implementation. An ACID compliant database will have to store uncommitted transaction data somewhere, and a disk-backed journal is an obvious choice.

The SQLite documentation includes an exhaustive explanation on how exactly it implements transactions.

like image 175
Martijn Pieters Avatar answered Sep 21 '22 17:09

Martijn Pieters