pgref.dev/sqlite/errors/SQLITE_READONLY_RECOVERY
SQLITE_READONLY_RECOVERYWARNINGTier 2 — Caution⚠️ MEDIUM confidence

Read-only: WAL recovery required by another connection

Category: Read-OnlyVersions: 3.7.0+

🔴 Production Risk Error

High — read-only connections cannot access the database until recovery completes.

What this means

SQLITE_READONLY_RECOVERY (264) is returned when a read-only connection attempts to open a WAL-mode database that requires WAL recovery (crash recovery), but because the connection is read-only it cannot perform the recovery.

Why it happens

  1. 1Database was opened read-only (O_RDONLY) but the WAL needs recovery after a crash.
  2. 2Read-only replica mount cannot write the -wal file during recovery.

How to reproduce

Read-only database file access with a pending WAL recovery.

trigger — this will ERROR
import sqlite3
conn = sqlite3.connect('file:my.db?mode=ro', uri=True)
# If WAL recovery needed: SQLITE_READONLY_RECOVERY
sqlite3.OperationalError: attempt to write a readonly database

Fix 1

Why this works

Open the database as read-write briefly to allow recovery to complete, then switch back to read-only.

Fix 2

Why this works

Ensure a read-write connection can open the database first to perform WAL recovery.

Sources

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

🔧 Source ref: sqlite3.h — SQLITE_READONLY_RECOVERY = 264

📖 Further reading: WAL mode

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 →