database
system_error
ai_generated
partial
sqlite3.OperationalError:磁盘 I/O 错误
sqlite3.OperationalError: disk I/O error
ID: database/sqlite-disk-io-error
75%修复率
87%置信度
1证据数
2023-04-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| SQLite 3.39 | active | — | — | — |
| SQLite 3.40 | active | — | — | — |
| SQLite 3.43 | active | — | — | — |
根因分析
SQLite 在读取或写入数据库文件时遇到操作系统级别的输入/输出错误,通常由文件系统损坏、磁盘故障或存储设备权限不足引起。
English
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.
官方文档
https://www.sqlite.org/rescode.html#ioerr解决方案
-
Run fsck on the filesystem (e.g., sudo fsck /dev/sda1) or on Windows run chkdsk /f C:. This may fix underlying corruption.
-
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.
-
Run: sqlite3 corrupted.db '.dump' | sqlite3 new.db. This recreates the database from scratch, skipping corrupted pages if possible.
无效尝试
常见但无效的做法:
-
100% 失败
The underlying I/O issue persists; reopening will trigger the same error immediately.
-
80% 失败
VACUUM requires a temporary file and may fail with the same I/O error if the disk is full or damaged.
-
90% 失败
WAL mode still writes to disk; if the disk is faulty, the error will recur.