3
When I created a database in Sqlite on Android, I noticed a file with the table name, followed by -Journal. What is it and what it’s for?
Strange this file have different permissions and use a table icon in an explorer application...
3
When I created a database in Sqlite on Android, I noticed a file with the table name, followed by -Journal. What is it and what it’s for?
Strange this file have different permissions and use a table icon in an explorer application...
2
The purpose of a Journal ("") is to ensure the atomicity changes made to the database data: say you have a transaction with 3 Inserts/updates/Letes; how to ensure that or all three succeed or the three of you fail? How to ensure that, for example, you do not subtract funds from one bank account and, before adding these funds to the other, the computer stops and those funds disappear?
This is done through a special file, which records all the transactions that are being carried out until the moment of its completion. An example (fictitious) would be:
iniciou transação
fez insert na tabela X com os valores A
fez insert na tabela Y com os valores B
fez update na tabela Z com os valores C; os valores antigos eram D
commit
When you start the transaction, the bank is in its original state; when you do the first insert
, it stores the new data in a temporary region (example; each bank can do it in a different way); idem pro segundo; idem pro pro update
; when you commit, it takes the data from the first insert
and put on the final table; idem pro segundo and pro update
; once ready, it erases the Journal.
What’s this all about? Simple:
Note that if there is no Journal on file, the atomicity of any transaction cannot be guaranteed! In the question indicated by Pope Charlie in the comments AP asks for a way to disable it (i.e. to cause the Journal exists only in memory / does not exist at all). If you don’t have a good reason to do this, don’t: otherwise, your transactions may be incomplete (unless of course you don’t have any complex transactions that require atomicity).
And if I haven’t been clear, this is even true for "transactions" with a single operation (I’m uncertain about operations out of of a transaction, but for security I would assume that is also the case). Quoting the documentation of Sqlite:
The mode of journaling
MEMORY
keeps the diary of rollbacks in volatile RAM. This saves disk I/O but at the expense of database security and integrity. If an application using Sqlite hangs in the middle of a transaction when modeMEMORY
is active, then probably the database file will get corrupted.The mode of journaling
OFF
disables the journal of rollbacks completely. No journal is created and therefore there is never a file to remove. (...) If an application using Sqlite hangs in the middle of a transaction when modeOFF
is active, then probably the database file will get corrupted.
Additional references:
Browser other questions tagged android sqlite
You are not signed in. Login or sign up in order to post.
Possible explanation here
– Papa Charlie