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?
3 Answers
From the command line, do this:
sqlite3 MyDatabase.sqlite
VACUUM;
- 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.
-
4There are two solutions proposed in this thread: (1) PRAGMA wal_checkpoint (2) VACUUM and exit. I too am working with Core Data. My main sqlite file was 46 MB and my -wal file was a whopping 1.2 GB. My results: PRAGMA wal_checkpoint or PRAGMA wal_checkpoint(1) have no effect. VACUUM reduced the size of the -wal file from 1.2 GB to 40.8 MB, and reduced the main sqlite from from 46 to 40.5 MB. Repeated executions of either command did not result in any further reductions. However, exitting the sqlite3 console reduced the -wal file to 0, as stated by Johannes. Aug 17, 2015 at 18:41
-
@JerryKrinock Hey Jerry, good to hear from you. That's really interesting! You might want to ask people on the sqlite mailing list about that and please update your comment when you find out why that's happening. Aug 17, 2015 at 19:34
-
4
-
1FYI:
VACUUM
rebuilds the database file to reduce it's size. sqlite.org/lang_vacuum.html– jl005Apr 25, 2021 at 23:22
Do a checkpoint, i.e., execute PRAGMA wal_checkpoint.
-
1On terminal run
sqlite3 db.sqlite
make sure that the directory contains-wal
file then runPRAGMA wal_checkpoint
and exit the db byctrl+d
Feb 15, 2017 at 17:07
In an app "DB Browser for SQLite" open a database and switch between Journal Mode from "WAL" to "Off" and tap a button "Apply", and switch back to "WAL".