Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge contents of SQLite 3.7 WAL file into main database file

Tags:

sqlite

ios7

wal

With WAL (Write-Ahead-Logging) enabled in SQLite 3.7 (which is the default for Core Data on iOS 7), how do I merge/commit the content from the -wal file back into the main database file?

like image 852
Johannes Fahrenkrug Avatar asked Oct 24 '13 18:10

Johannes Fahrenkrug


People also ask

What is a SQLite WAL file?

The WAL file is part of the persistent state of the database and should be kept with the database if the database is copied or moved. If a database file is separated from its WAL file, then transactions that were previously committed to the database might be lost, or the database file might become corrupted.

Can SQLite store an entire database in a single file?

Afaik, SQLite stores a single database in a single file.

What is WAL format?

The write-ahead log or "wal" file is a roll-forward journal that records transactions that have been committed but not yet applied to the main database. Details on the format of the wal file are describe in the WAL format subsection of the main file format document.


2 Answers

From the command line, do this:

  1. sqlite3 MyDatabase.sqlite
  2. VACUUM;
  3. CTRL-D to exit the sqlite console.

Done!

The -wal file should now have a size of 0 and everything should be in your main database file.

like image 135
Johannes Fahrenkrug Avatar answered Oct 03 '22 09:10

Johannes Fahrenkrug


Do a checkpoint, i.e., execute PRAGMA wal_checkpoint.

like image 35
CL. Avatar answered Oct 03 '22 10:10

CL.