postgresql postgres 中的共享缓冲区

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6175644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:03:08  来源:igfitidea点击:

Shared buffer in postgres

postgresql

提问by pree

I am curious about the role played by shared buffer in postgres. Shared buffer maintains all the recently accessed disk pages and dirty pages. If a new page needs to be brought in and there is no space left in shared buffer, a victim dirty page is written back to the disk.

我很好奇共享缓冲区在 postgres 中的作用。共享缓冲区维护所有最近访问的磁盘页面和脏页面。如果需要引入新页面并且共享缓冲区中没有剩余空间,则会将受害者脏页面写回磁盘。

However, I am confused about this statement- PostgreSQL depends on the OS for caching. (http://www.varlena.com/GeneralBits/Tidbits/perf.html#shbuf)"

但是,我对这句话感到困惑——PostgreSQL 依赖于操作系统进行缓存。(http://www.varlena.com/GeneralBits/Tidbits/perf.html#shbuf)”

How does postgres depends on the OS for caching? And how does it change the behavior of shared buffer?

postgres 如何依赖操作系统进行缓存?它如何改变共享缓冲区的行为?

回答by Guillaume Savary

Postgresql uses the OS cache and its own data cache. The two are useful according to your database usage.

Postgresql 使用操作系统缓存和它自己的数据缓存。根据您的数据库使用情况,这两个很有用。

OS cache is very fast but basic: it removes older data with the new one. It is useful for very versatile query results. PG cache is slower (still much faster than disk) but it keeps usage counters of the most used data. Useful for recurrent results/index.

操作系统缓存非常快但很基本:它会用新数据删除旧数据。它对于非常通用的查询结果很有用。PG 缓存较慢(仍然比磁盘快得多)但它保留最常用数据的使用计数器。对重复结果/索引有用。

回答by Mathias Brossard

I think this linkis clearer (and more up-to-date).

我认为这个链接更清晰(而且更新)。

My understanding is that shared_buffers is where PostgreSQL processes work and share information, but above a certain limit (15% to 25% of the server RAM) diminishing returns makes it more interesting to leave more RAM to the OS to perform caching itself.

我的理解是 shared_buffers 是 PostgreSQL 处理工作和共享信息的地方,但是超过某个限制(服务器 RAM 的 15% 到 25%),收益递减使得将更多 RAM 留给操作系统来执行缓存本身变得更有趣。