Monty
Monty

Reputation: 3215

SQLite database files

I want to know why SQLite create two file inside the path.and what is the diffrence these files.

I have a database name mydatabase.

when i see in given path there are two files.

data/data/pack name/databases/....

1- mydatabase

2- mydatabase-journal

Upvotes: 0

Views: 514

Answers (1)

mvp
mvp

Reputation: 116078

mydatabase is main database file, which contains everything about that database.

mydatabase-journal is journal file. It does not exist by default, and only gets created by SQLite when necessary to keep intent log of what SQLite wants to do with database. Basically, this is intent of what should be done to main database file after transaction is properly finished. If you finish all transactions normally and disconnect from database gracefully, -journal file will be normally removed automatically.

If disconnect was abrupt - like process killed or crashed, -journal file will remain and should NOT be deleted. When next time SQLite opens this database once again, it will notice presence of -journal file and will replay or rollback unfinished transactions, such that main database file is consistent and not corrupted.

If you remove -journal file manually, recovery is not guaranteed and database may be completely corrupted - so, DO NOT remove -journal files.

Probably easiest way to properly get rid of -journal files is to do this command:

sqlite3 mysqlitedatabase.db VACUUM

It will VACUUM (optimize) your database and should leave only main file as a result.

Upvotes: 1

Related Questions