Fix SQLite Error: 'SQLITE_BUSY: database is locked'
Resolve SQLite file lock contention during concurrent write transactions by enabling Write-Ahead Logging (WAL) and setting busy_timeout.
SqliteError: database is locked (code 5, SQLITE_BUSY)
// Better-SQLite3 / Prisma SQLite WAL Configuration
import Database from 'better-sqlite3';
const db = new Database('app.db', { timeout: 5000 });
// 1. Enable Write-Ahead Logging for high concurrency
db.pragma('journal_mode = WAL');
// 2. Set retry timeout to prevent immediate lock exceptions
db.pragma('busy_timeout = 5000');
// 3. Normal synchronous mode provides optimal performance with WAL
db.pragma('synchronous = NORMAL');Root Cause & Mechanism Analysis
Why does this error occur?
SQLite is a serverless single-file database. Standard rollback journal locks the entire database file during writes. Multiple concurrent processes trying to write simultaneously trigger SQLITE_BUSY.
Frequently Asked Questions
What is WAL mode in SQLite?
Related Developer Error Solutions
Browse All 35 GuidesPostgreSQL: Remaining Connection Slots Reserved
Resolve PostgreSQL connection exhaustion caused by connection leaks or missing pooling with PgBouncer / Prisma Accelerate.
Prisma Error P1001: Can't Reach Database
Troubleshoot network connectivity, SSL certificates, wrong port mappings, and environment variable issues with Prisma ORM.
Node.js: JavaScript heap out of memory
Increase V8 memory allocation using --max-old-space-size and identify memory leaks during builds.