pgref.dev/sqlite/errors/SQLITE_IOERR_LOCK
SQLITE_IOERR_LOCKERRORTier 2 — Caution⚠️ MEDIUM confidence

I/O error obtaining file lock

Category: I/O ErrorVersions: 3.0+

🔴 Production Risk Error

High — transaction cannot proceed; use local storage.

What this means

SQLITE_IOERR_LOCK (3850) is returned when the OS reports an error while SQLite is trying to acquire a file lock — distinct from SQLITE_BUSY, which indicates the lock is held by another process.

Why it happens

  1. 1Filesystem does not support POSIX advisory locks (some network filesystems).
  2. 2OS error (EIO, ENOMEM) during fcntl() lock call.
  3. 3Docker or container environment with non-standard file locking.

How to reproduce

Lock acquisition during BEGIN EXCLUSIVE or BEGIN IMMEDIATE.

trigger — this will ERROR
# On NFS or some Docker volumes, fcntl() may return EIO
# → SQLITE_IOERR_LOCK instead of SQLITE_BUSY
sqlite3.OperationalError: disk I/O error

Fix 1

Why this works

Use a local filesystem for SQLite databases.

Fix 2

Why this works

Use WAL mode which uses shared-memory instead of file locks for readers.

Fix 3

Why this works

Set locking_mode=EXCLUSIVE if single-writer access is guaranteed.

What not to do

Why it's wrong:

Sources

📚 Official docs: https://www.sqlite.org/rescode.html#ioerr_lock

🔧 Source ref: sqlite3.h — SQLITE_IOERR_LOCK = 3850

📖 Further reading: SQLite file locking

Confidence assessment

⚠️ MEDIUM confidence

Stable.

See also

⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →