A -wal file next to a SQLite database is not leftover junk while the database is in use. It holds committed transactions that have not yet been copied into the main file. Deleting it while the database is closed after a crash removes those commits. Deleting it from a database that was shut down cleanly is harmless, but in that case SQLite has already deleted it for you.

The -shm file is a small shared-memory index of the -wal file. It matters only while connections are open. The question most people actually have, why the -wal file is 100 MB, has a specific cause: a checkpoint that cannot finish because something is still reading.

Last checked November 26, 2026. The sizes below come from a Python script run against SQLite 3.53.1 on Linux, with the default 4,096-byte page size and 500-byte rows. Your numbers will differ with row size, but the pattern and the rules come from the SQLite WAL documentation.

What the three files hold

File What is in it When it exists
app.db The database file. Holds everything up to the last completed checkpoint. Always
app.db-wal The write-ahead log: every changed page since the last checkpoint, with a 32-byte header and then one frame per page (a 24-byte frame header plus the page). While any connection has the database open. Normally deleted when the last connection closes.
app.db-shm The wal-index, a shared-memory file that lets processes find pages in the log quickly. While any connection is open. Deleted when the last one disconnects.

The documentation says 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.” It also warns that if a database file is separated from its WAL file, “transactions that were previously committed to the database might be lost, or the database file might become corrupt.”

The frame size explains the numbers below. With 4,096-byte pages, each frame is 4,120 bytes, so a WAL of 1,001 frames is 32 + 1,001 × 4,120 = 4,124,152 bytes. That is the exact size my test showed.

Why a normal WAL stops near 4 MB

By default SQLite runs a checkpoint after a commit once the log passes 1,000 pages. A checkpoint copies pages from the log back into the database file. The log is then reused from the start, not shrunk. The documentation puts it as “about 4MB in size”, and the wal_autocheckpoint pragma shows the threshold in your connection.

I opened a fresh database in WAL mode and committed one 500-byte row at a time:

Step .db -wal -shm
After creating one table 4,096 8,272 32,768
After 200 single-row commits 4,096 1,034,152 32,768
After 20,200 single-row commits 10,235,904 4,124,152 32,768

The largest WAL size seen at any point in the 20,000-commit loop was 4,124,152 bytes. The main file grew to 10 MB while the log stayed at about 4 MB, which is the checkpoint doing its job. Sizes are in bytes.

What makes the WAL grow past that

A checkpoint can copy only up to the point that the oldest open read transaction can still see. The documentation says a checkpoint “must stop when it reaches a page in the WAL that is past the end mark of any current reader”, and that a database with overlapping readers can make the WAL “grow without bound.” Very large write transactions do the same, since a log cannot be reset in the middle of one.

I reproduced the reader case. One connection started a read transaction and kept it open, and a second connection committed 20,000 more rows:

Step .db -wal -shm
Reader open, 20,000 more commits 10,375,168 103,630,392 229,376
PRAGMA wal_checkpoint(PASSIVE) result (0, 25153, 0): 25,153 frames in the log, 0 moved to the database
Reader closed, one more commit 20,643,840 103,642,752 229,376

Three things stand out. The WAL reached 103,630,392 bytes, about 25 times the usual ceiling. The checkpoint result shows no frame could be moved while the reader was open. And once the reader ended, the next commit did checkpoint (the main file jumped from 10 MB to 20 MB), yet the -wal file did not get smaller. SQLite reuses the file for later writes instead of truncating it, as the journal_size_limit pragma documentation explains: “in WAL mode, the write-ahead log file is not truncated following a checkpoint.”

The -shm file grew too, from 32 KiB to 224 KiB, because the index tracks every frame.

How to shrink it

Goal Statement Result in my test
Shrink once, now PRAGMA wal_checkpoint(TRUNCATE); WAL went from 103,642,752 bytes to 0 and returned (0, 0, 0)
Keep the leftover file small after every reset PRAGMA journal_size_limit = 6144000; Not tested; the documentation says SQLite truncates the file to the limit when the log resets
Stop growth at the source End read transactions promptly; avoid one huge write transaction The cause above

TRUNCATE works like RESTART, which waits for readers to finish, then truncates the log. The wal_checkpoint documentation lists four modes: PASSIVE never waits, FULL and RESTART block writers while they run, and TRUNCATE also cuts the file to zero. If another connection is still reading, the first result column is 1 and the log is not reset. The SQLite documentation suggests manual RESTART or TRUNCATE checkpoints for applications with many overlapping readers, with the trade-off that readers may block while it runs.

After every connection closed in my test, both -wal and -shm were gone from the directory.

What deleting the -wal file does

A clean shutdown checkpoints and removes the log, so a leftover -wal after a normal close usually means the process died or something kept a connection open. I tested what a crash leaves. A child process committed 1,000 single-row transactions and then exited without closing the connection:

Step Rows readable
Copy of app.db alone 995
Copy of app.db and app.db-wal together 1,000
Original, after deleting -wal and -shm 995

Five committed rows existed only in the log. Copying the main file by itself, or deleting the log “to clean up”, lost them without any error. With default settings the exposure is whatever has been committed since the last checkpoint, up to about 1,000 pages. SQLite’s corruption guide says the same about copying: if a previous write transaction failed, any -journal or -wal file must be copied together with the database file, and deleting a hot journal file after a crash can corrupt the database.

I did not test deleting -shm on its own. The documentation describes it as an index that is “never synced” and removed when the last connection disconnects, which is why the -wal file is the one to protect.

Safe ways to back up or move the file

  1. Use the .backup command or the backup API in the sqlite3 shell; they handle the log while the database is in use.
  2. Run VACUUM INTO 'copy.db' for a single compacted file; the documentation says the output is a consistent snapshot of the original database.
  3. If you copy files, close every connection first, so the shutdown checkpoint leaves one file, or copy -wal together with the main file.
  4. Do not put a WAL database on a network share. The documentation states that WAL requires all processes to be on the same host, because the wal-index relies on shared memory.

For apps that keep their data in a local SQLite file, the same reasoning applies to backups of the whole data folder. Our guide to local-first apps covers the difference between a local copy, sync and a backup.

Reproduce the test

import sqlite3, os
db = "app.db"
c = sqlite3.connect(db, isolation_level=None)
c.execute("pragma journal_mode=wal")
c.execute("create table t(id integer primary key, v text)")
for _ in range(20000):
    c.execute("insert into t(v) values(?)", ("x" * 500,))
print(os.path.getsize(db + "-wal"))   # about 4 MB
r = sqlite3.connect(db, isolation_level=None)
r.execute("begin"); r.execute("select count(*) from t").fetchone()
for _ in range(20000):
    c.execute("insert into t(v) values(?)", ("x" * 500,))
print(os.path.getsize(db + "-wal"))   # about 100 MB while the reader is open
print(c.execute("pragma wal_checkpoint(PASSIVE)").fetchone())
r.execute("commit")
print(c.execute("pragma wal_checkpoint(TRUNCATE)").fetchone())
print(os.path.getsize(db + "-wal"))   # 0