pgref.dev/sqlite/errors/SQLITE_PERM
SQLITE_PERMERRORTier 2 — Caution⚠️ MEDIUM confidence

Access permission denied

Category: PermissionsVersions: 3.0+

🔴 Production Risk Error

High — all writes will fail until permissions are corrected.

What this means

SQLITE_PERM (3) is returned when the OS denies access to a file that SQLite needs to open or create. The file exists but the process lacks read or write permission.

Why it happens

  1. 1Database file owned by a different user with no group/world permissions.
  2. 2Read-only filesystem (e.g., Docker volume mounted read-only).
  3. 3SELinux or AppArmor policy blocking file access.
  4. 4WAL journal file or shm file not writable.

How to reproduce

Occurs on sqlite3_open() or the first write operation if permissions changed after open.

trigger — this will ERROR
import os, sqlite3
os.chmod('my.db', 0o000)
try:
    sqlite3.connect('my.db')
except sqlite3.OperationalError as e:
    print(e)  # unable to open database file
sqlite3.OperationalError: unable to open database file

Fix 1

Why this works

Check file and parent directory permissions: ls -la my.db

Fix 2

Why this works

Fix ownership: chown appuser:appuser my.db

Fix 3

Why this works

Fix permissions: chmod 664 my.db

Fix 4

Why this works

Ensure the WAL sidecar files (-wal, -shm) are also writable.

What not to do

Why it's wrong:

Sources

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

🔧 Source ref: sqlite3.h — SQLITE_PERM = 3

📖 Further reading: SQLite file locking and concurrency

Confidence assessment

⚠️ MEDIUM confidence

Stable. Standard OS permission denial.

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 →