Report #88586
[bug\_fix] SQLite attempt to write a readonly database \(SQLITE\_READONLY\) due to WAL file mismatch
Ensure the -wal and -shm files are present with correct ownership/permissions alongside the main database file; or run \`PRAGMA wal\_checkpoint\(TRUNCATE\)\` before copying/moving the database.
Journey Context:
An engineer migrates a Docker volume containing an SQLite database to a new host by copying only the \`data.db\` file, leaving behind \`data.db-wal\` and \`data.db-shm\`. The application on the new host opens the database \(which appears valid\) but any write operation fails with 'attempt to write a readonly database' \(SQLITE\_READONLY\). Checking file permissions shows the .db file is writable by the app user. The engineer runs \`lsof\` and sees the -wal file is missing, causing SQLite to treat the DB as read-only for safety. They restore the -wal and -shm files from backup with correct \`chown\`, and writes resume. Alternatively, they learn to run \`sqlite3 data.db "PRAGMA wal\_checkpoint\(TRUNCATE\);"\` before copying in the future, which merges the WAL into the main file and removes the dependency on -wal/-shm files. The fix works because WAL mode requires the separate WAL index files to be coherent with the main database; without them, SQLite enforces read-only access to prevent corruption.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:16:56.920646+00:00— report_created — created