pgref.dev/sqlite/errors/SQLITE_READONLY_DBMOVED
SQLITE_READONLY_DBMOVEDERRORTier 2 — Caution⚠️ MEDIUM confidence

Read-only: database file has been moved

Category: Read-OnlyVersions: 3.11.0+

🔴 Production Risk Error

High — writes will fail until the connection is re-opened on the new path.

What this means

SQLITE_READONLY_DBMOVED (1032) is returned when SQLite detects that the database file has been moved or renamed since it was opened, making it impossible to safely write to the file.

Why it happens

  1. 1Another process renamed or moved the database file while a connection was open.
  2. 2Atomic file replacement pattern (rename-to-final) used while SQLite has the old file open.

How to reproduce

Write operation on a file whose path no longer matches its inode.

trigger — this will ERROR
import os, sqlite3
conn = sqlite3.connect('my.db')
os.rename('my.db', 'my.db.bak')
try:
    conn.execute('INSERT INTO t VALUES(1)')
except sqlite3.OperationalError as e:
    print(e)  # attempt to write a readonly database
sqlite3.OperationalError: attempt to write a readonly database

Fix 1

Why this works

Do not rename or move a SQLite database file while connections are open.

Fix 2

Why this works

Close all connections before performing file-level operations on the database.

Fix 3

Why this works

Use WAL mode snapshots or VACUUM INTO to create copies without renaming the live file.

What not to do

Why it's wrong:

Version notes

Sources

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

🔧 Source ref: sqlite3.h — SQLITE_READONLY_DBMOVED = 1032

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 →