53100
database
resource_error
ai_generated
true
psycopg2.OperationalError: 错误:无法创建临时文件:设备上没有剩余空间 提示:您可能需要增加 max_files_per_process 限制。
psycopg2.OperationalError: ERROR: could not create temporary file: No space left on device HINT: You might need to increase the max_files_per_process limit.
ID: database/temp-file-limit-exceeded
80%修复率
85%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| PostgreSQL 12 | active | — | — | — |
| PostgreSQL 13 | active | — | — | — |
| PostgreSQL 14 | active | — | — | — |
| PostgreSQL 15 | active | — | — | — |
| PostgreSQL 16 | active | — | — | — |
根因分析
PostgreSQL 已耗尽了临时文件目录中的磁盘空间或内核的文件描述符限制,导致无法为查询执行创建临时文件。
English
PostgreSQL has exhausted either disk space in the temporary file directory or the kernel's file descriptor limit, preventing the creation of temporary files for query execution.
官方文档
https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-MAX-FILES-PER-PROCESS解决方案
-
使用 `df -h` 和 `df -i` 检查包含 pg_stat_tmp 和 base 目录的分区磁盘使用情况。通过删除旧的 WAL 文件或归档日志来释放空间:`pg_archivecleanup /path/to/archive $(ls -t /path/to/archive | tail -1)`
-
向临时目录添加更多磁盘空间或挂载更大的卷。然后重启 PostgreSQL,或将 temp_tablespaces 设置为空间充足的卷上的表空间:`ALTER SYSTEM SET temp_tablespaces = 'fast_disk'; SELECT pg_reload_conf();`
-
如果问题是文件描述符限制,在 postgresql.conf 中增加 max_files_per_process 并重启:`ALTER SYSTEM SET max_files_per_process = 2000;` 然后重启服务器
无效尝试
常见但无效的做法:
-
Increase max_files_per_process in postgresql.conf without checking disk space
60% 失败
The error is usually caused by full disk, not file descriptor limit; raising max_files_per_process won't free disk space
-
Delete random files from pg_tblspc thinking they are temporary
80% 失败
pg_tblspc contains symbolic links to tablespaces; deleting them can corrupt the database
-
Restart PostgreSQL without clearing temp files
70% 失败
Restarting doesn't reclaim disk space; the underlying issue of full disk or exhausted inodes remains