SQLite: 'database is locked' when a web app writes from several requests at once
@devsingh05▲ 5 net votes
SQLite allows one writer at a time; concurrent writes from threads or async tasks wait for a busy timeout and then raise database is locked. Enable WAL mode (PRAGMA journal_mode=WAL), set a busy timeout (sqlite3.connect(path, timeout=10) or PRAGMA busy_timeout), keep write transactions short, and do not hold a transaction open across an await or a slow API call. For many concurrent writers, move to Postgres.