Use*_*er1 3 postgresql optimization
Postgres中的work_mem选项如何工作?以下是http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html中的描述:
Specifies the amount of memory to be used by internal sort operations and hash tables before switching to temporary disk files. The value defaults to one megabyte (1MB). Note that for a complex query, several sort or hash operations might be running in parallel; each one will be allowed to use as much memory as this value specifies before it starts to put data into temporary files. Also, several running sessions could be doing such operations concurrently. So the total memory used could be many times the value of work_mem; it is necessary to keep this fact in mind when choosing the value. 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 IN subqueries.
我可能完全错了,但是......不是"切换到临时磁盘文件"与操作系统中的"虚拟内存"基本相同吗?一旦RAM消失,OS是否只会创建一个交换文件?将它设置为类似于100TB并让操作系统弄清楚它会不会更好?在我可能弄乱我的系统之前,我想检查是否有人真正尝试过这种方法.
例如,如果知道排序将发生在磁盘上,PostgreSQL将转换为更适合磁盘排序而不是内存排序的排序操作 - 它不知道它是否发生在交换中.
此外,如果PostgreSQL发现数据不适合RAM,则可以切换到完全不同的计划(例如,使用不同的JOIN方法).
只要有足够的数据,将 work_mem设置得太高就会让你的数据库非常慢,这样一切都不再适合RAM.
请记住,这work_mem是每个排序操作可以使用的最大RAM量.对于单个查询,多个排序操作可能并行运行,并且可能有多个连接一次查询数据库.因此,所有排序操作可能会使用RAM中work_mem的x倍(这是推荐保守金额的原因).
现在回到你的问题,如果你选择一个work_mem如此高的值,排序操作可能会占用你的大部分RAM,这导致从交换页面输入和输出(请记住,有很多其他进程和PostgreSQL部分,需要一些(甚至很多)RAM.基于磁盘的排序操作比操作系统完成的页面交换更有效.正如其他一些回复指出的那样,一个已经交换掉的数据库服务器将不断地执行慢.
另一点是,具有如此高的work_mem值,单个查询(故意或偶然)可能或多或少地使整个数据库服务器无响应.
| 归档时间: |
|
| 查看次数: |
5147 次 |
| 最近记录: |