From edd9d233bc45255c8b7cbffd3066b458ae401cff Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Fri, 21 Feb 2025 19:24:04 +1100 Subject: [PATCH] Add SQLite write timeout to reduce "database locked" errors This allows write requests to queue. I've also documented the one-off change to enable WAL mode. --- conservancy/settings/prod.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conservancy/settings/prod.py b/conservancy/settings/prod.py index 35b9b52b..c633ddab 100644 --- a/conservancy/settings/prod.py +++ b/conservancy/settings/prod.py @@ -20,6 +20,13 @@ DATABASES = { 'default': { 'NAME': '/var/lib/www/database/conservancy-website.sqlite3', 'ENGINE': 'django.db.backends.sqlite3', + # WAL mode allows concurrent reading and writing. It is enabled permanently with: + # sudo -u www-data sqlite3 conservancy-website.sqlite3 'PRAGMA journal_mode=WAL;' + 'OPTIONS': { + # Reduce the incidence of "database locked" errors by allowing write + # requests to be queued for some seconds. + 'timeout': 5, + }, } }