database system_error ai_generated partial

sqlite3.OperationalError: disk I/O error

ID: database/sqlite-disk-io-error

Also available as: JSON · Markdown · 中文
75%Fix Rate
87%Confidence
1Evidence
2023-04-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
SQLite 3.39 active
SQLite 3.40 active
SQLite 3.43 active

Root Cause

SQLite encounters an operating system-level input/output error while reading or writing the database file, typically due to filesystem corruption, disk failure, or insufficient permissions on the storage device.

generic

中文

SQLite 在读取或写入数据库文件时遇到操作系统级别的输入/输出错误,通常由文件系统损坏、磁盘故障或存储设备权限不足引起。

Official Documentation

https://www.sqlite.org/rescode.html#ioerr

Workarounds

  1. 70% success Run fsck on the filesystem (e.g., sudo fsck /dev/sda1) or on Windows run chkdsk /f C:. This may fix underlying corruption.
    Run fsck on the filesystem (e.g., sudo fsck /dev/sda1) or on Windows run chkdsk /f C:. This may fix underlying corruption.
  2. 80% success Copy the .db file to another disk: cp mydb.db /healthy_disk/mydb.db. Then run: sqlite3 /healthy_disk/mydb.db 'PRAGMA integrity_check;'. If it passes, use the copy.
    Copy the .db file to another disk: cp mydb.db /healthy_disk/mydb.db. Then run: sqlite3 /healthy_disk/mydb.db 'PRAGMA integrity_check;'. If it passes, use the copy.
  3. 75% success Run: sqlite3 corrupted.db '.dump' | sqlite3 new.db. This recreates the database from scratch, skipping corrupted pages if possible.
    Run: sqlite3 corrupted.db '.dump' | sqlite3 new.db. This recreates the database from scratch, skipping corrupted pages if possible.

中文步骤

  1. Run fsck on the filesystem (e.g., sudo fsck /dev/sda1) or on Windows run chkdsk /f C:. This may fix underlying corruption.
  2. Copy the .db file to another disk: cp mydb.db /healthy_disk/mydb.db. Then run: sqlite3 /healthy_disk/mydb.db 'PRAGMA integrity_check;'. If it passes, use the copy.
  3. Run: sqlite3 corrupted.db '.dump' | sqlite3 new.db. This recreates the database from scratch, skipping corrupted pages if possible.

Dead Ends

Common approaches that don't work:

  1. 100% fail

    The underlying I/O issue persists; reopening will trigger the same error immediately.

  2. 80% fail

    VACUUM requires a temporary file and may fail with the same I/O error if the disk is full or damaged.

  3. 90% fail

    WAL mode still writes to disk; if the disk is faulty, the error will recur.