# sqlite3.DatabaseError: 磁盘I/O错误

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

## 根因

SQLite遇到了文件系统级别的读取或写入失败，通常是由于磁盘损坏、权限不足或文件系统已满。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| SQLite 3.40 | active | — | — |
| SQLite 3.41 | active | — | — |
| SQLite 3.42 | active | — | — |
| Python 3.11 | active | — | — |
| Python 3.12 | active | — | — |

## 解决方案

1. ```
   Check filesystem health using fsck (Linux) or chkdsk (Windows). Example: sudo fsck /dev/sda1 or chkdsk C: /f. Then attempt to recover the database using sqlite3 .recover.
   ```
2. ```
   If the error is due to permissions, ensure the SQLite process has write access to the database file and its directory. Example: chmod 664 /path/to/database.db && chown www-data:www-data /path/to/database.db
   ```
3. ```
   Use SQLite's built-in integrity check and repair: sqlite3 database.db "PRAGMA integrity_check;" then backup and restore: sqlite3 database.db ".backup backup.db"
   ```

## 无效尝试

- **Delete the database file and recreate it from scratch.** — This causes data loss and does not address the underlying disk issue; the new file may also get corrupted if the root cause persists. (90% 失败率)
- **Increase the SQLite cache size to reduce disk writes.** — Cache size adjustments do not fix physical disk I/O errors; they only affect performance, not reliability. (80% 失败率)
