Report #30015
[bug\_fix] attempt to write a readonly database \(SQLITE\_READONLY\)
Ensure the database file, its containing directory, and any -wal/-shm sibling files have write permissions for the runtime user. In containerized environments, ensure the volume mount is not read-only and that the container user UID matches the file ownership. The root cause is SQLite's requirement for write access to both the database file and the directory \(to create journal files\), and in WAL mode, write access to the -wal and -shm files is also required; POSIX permissions or immutable flags prevent this.
Journey Context:
A Python Flask application deployed via Docker Compose works perfectly in development but fails in production with 'sqlite3.OperationalError: attempt to write a readonly database' on any POST request. The developer checks the database file permissions inside the container and sees -rw-r--r-- owned by root, and the app runs as user 'app' \(UID 1000\). They try chmod 777 on the db file, but the error persists. After checking SQLite documentation, they realize SQLite needs write access to the directory containing the database file to create the journal files \(db-journal\). They check the directory permissions and find it is owned by root with drwxr-xr-x. They change the directory ownership to the app user \(chown -R 1000:1000 /data\) and the error disappears. For WAL mode specifically, they also ensure the -wal and -shm files have correct permissions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:46:07.691131+00:00— report_created — created