SQLITE_READONLY_CANTLOCK
SQLiteWARNINGNotableRead-Onlyofficial confidence

Read-only: unable to obtain shared lock

Production Risk

Medium — reads will fail on constrained mounts.

What this means

SQLITE_READONLY_CANTLOCK (520) is returned when a read-only connection cannot acquire the shared lock needed to start a read transaction, because the shared-lock byte cannot be written (the file is read-only).

Why it happens
  1. 1Database file is on a read-only filesystem that does not support the lock byte mechanism.
  2. 2Shared-cache mode on a read-only file.
How to reproduce

Read-only filesystem mount, certain Docker or Kubernetes volume configurations.

trigger — this will error
trigger — this will error
# Mount a database read-only where lock bytes cannot be written
import sqlite3
conn = sqlite3.connect('file:/ro/my.db?mode=ro', uri=True)
conn.execute('SELECT 1')  # May raise SQLITE_READONLY_CANTLOCK

expected output

sqlite3.OperationalError: unable to open database file

Fix 1

Fix 2

Sources
Official documentation ↗

sqlite3.h — SQLITE_READONLY_CANTLOCK = 520

SQLite URI filenames

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All SQLite errors