Syncing the WAL with SQLite

Featured image for sharing metadata for article

When you're working with SQLite, it's possible that you're using the Write Ahead Log (WAL) to improve performance of the database.

As part of this, you may notice that your SQLite database goes from a single-file database like dmd.db to a multi-file setup:

% ls -lrt dmd.db*
........................ 577536 Jul 29 11:47 dmd.db
........................  32768 Jul 29 11:51 dmd.db-shm
........................ 646872 Jul 29 11:51 dmd.db-wal

This is absolutely fine, and most tools support this.

I recently found that the Dependency Management Data example project's build on GitLab CI was archiving the database (to then be downloaded) without the other files needed, and so we were seeing partial data.

I didn't want to store all three files, and instead only have the single dmd.db as the source of truth.

Alternatively, sometimes you want to be able to leverage one of the great things about SQLite - being able to have a single file that you can i.e. send someone on Slack.

To do this, we need to perform an SQLite WAL checkpoint, which can be triggered i.e. via

% sqlite3 dmd.db 'PRAGMA wal_checkpoint(FULL);'
(output not relevant)

This then takes your WAL'd database, and will sync the data from the WAL to the database.

Note that - as you may expect - this has performance implications while undergoing the checkpoint, and care should be taken when performing this on a live database.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #sqlite.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.