Report #93808
[bug\_fix] attempt to write a readonly database
Ensure the database file, its parent directory, and any existing WAL/shm files \(-wal, -shm\) are owned by the user running the application \(chown appuser:appgroup\), and that the directory is writable \(chmod 755\) because SQLite needs to create temporary journal files in the same directory.
Journey Context:
A Python application runs perfectly when started manually by the developer \(root\), but when systemd starts it as the 'www-data' user, all database writes fail with 'attempt to write a readonly database'. The developer first checks the database file permissions with 'ls -l' and sees '-rw-r--r-- 1 root root', confirming that www-data has no write access. They change the owner to www-data with 'chown www-data:www-data /var/lib/app/db.sqlite3', but the error persists. Investigating further with 'ls -la', they discover a stale 'db.sqlite3-journal' file owned by root from a previous interrupted transaction. Because www-data cannot delete or write to this journal file, SQLite refuses to start a new transaction. Finally, they realize that the directory /var/lib/app itself is owned by root with 755 permissions, meaning www-data cannot create new WAL files \(-wal\) or shared memory files \(-shm\) when WAL mode is enabled. The complete fix requires chowning the directory, the database file, and removing any stale root-owned journal/WAL files.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:02:43.396637+00:00— report_created — created