# sqlite3.OperationalError：磁盘 I/O 错误

- **ID:** `database/sqlite-disk-io-error`
- **领域:** database
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| SQLite 3.39 | active | — | — |
| SQLite 3.40 | active | — | — |
| SQLite 3.43 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — The underlying I/O issue persists; reopening will trigger the same error immediately. (100% 失败率)
- **** — VACUUM requires a temporary file and may fail with the same I/O error if the disk is full or damaged. (80% 失败率)
- **** — WAL mode still writes to disk; if the disk is faulty, the error will recur. (90% 失败率)
