gpt4 book ai didi

optimization - 当 Postgres 的 work_mem 达到最大值时会发生什么?

转载 作者:行者123 更新时间:2023-11-29 11:37:41 25 4
gpt4 key购买 nike

Postgres 中的 work_mem 选项如何工作?这是来自 http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html 的描述:

Specifies the amount of memory to be used by internalsort operations and hash tables before switching totemporary disk files. The value defaults to one megabyte(1MB). Note that for a complex query, several sort orhash operations might be running in parallel; each onewill be allowed to use as much memory as this valuespecifies before it starts to put data into temporary files. Also, several running sessions could be doingsuch operations concurrently. So the total memory usedcould be many times the value of work_mem; it isnecessary to keep this fact in mind when choosing thevalue. Sort operations are used for ORDER BY, DISTINCT,and merge joins. Hash tables are used in hash joins,hash-based aggregation, and hash-based processing of INsubqueries. 

我在这里可能完全错了但是..“切换到临时磁盘文件”在本质上与操作系统中的“虚拟内存”不是一回事吗?一旦 RAM 消失,操作系统不会创建一个交换文件吗?将其设置为 100TB 之类的值并让操作系统自行判断不是更好吗?在我可能搞砸我的系统之前,我想检查是否有人真正尝试过这种方法。

最佳答案

例如,如果 PostgreSQL 知道排序将发生在磁盘上,它将切换到更适合磁盘排序而不是内存排序的排序操作——它不会知道是否发生在交换中。

此外,如果 PostgreSQL 发现数据不适合 RAM,它可以切换到完全不同的计划(例如,使用不同的 JOIN 方法)。

将 work_mem 设置得太高在您有足够的数据时立即让您的数据库变得非常慢,以至于所有内容不再总是适合 RAM。

关于optimization - 当 Postgres 的 work_mem 达到最大值时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1196068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com