开发者社区> 问答> 正文

PostgreSQL 为什么临时文件这么大,怎么处理

我使用PostgreSQL 9.2 版本,发现tmp文件高达了100G。为什么会出现这种情况,怎么处理?

展开
收起
卓刀 2018-03-19 22:46:53 5149 0
1 条回答
写回答
取消 提交回答
  • PostgreSQL你值得拥有。

    如果有笛卡尔乘积或者大表的排序或者hash表的操作,会使用临时文件来存储中间过程的数据。如果频繁的进行上述操作,临时文件会快速增长。重启PostgreSQL可以解决这个问题。另外建议用户设置temp_file_limit 为磁盘空间的10 %。

    temp_file_limit的详细解释如下:
    Enter temp_file_limit, a parameter added by Mark Kirkwood to PostgreSQL 9.2. This is a limit on per-session usage of temporary files for sorts, hashes, and similar operations.
    If a user goes over the limit, their query gets cancelled and they see an error. This is an excellent way to prevent a single user, or a bad application change, from DOSing your database server. Set it to something high; I'm using 10GB or 20GB, or 10% of available disks space, whichever is less. But even a high limit like that will save you from some unexpected downtime.

    2019-07-17 22:02:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PostgresChina2018_赖思超_PostgreSQL10_hash索引的WAL日志修改版final 立即下载
为什么PostgreSQL是最适合去O的数据库 立即下载
阿里云MongoDB备份恢复功能说明和原理介绍 立即下载