英文:
Does PostgreSQL Vacuum Cause Buffer Cache Hit Ratio to Dip?
问题
Most of the time, our PostgreSQL (version 13.8, AWS Aurora, PostgreSQL compatible) database's buffer cache hit ratio has been somewhere around 95~98%. However, we have been observing an occasional dip in the buffer cache hit ratio to 70%-80%. I managed to track the occurrences of these dips to vacuum activity. Whenever there's vacuum activity, we see the buffer cache hit ratio dip to 70-80%.
我們的PostgreSQL(版本13.8,AWS Aurora,PostgreSQL兼容)數據庫的緩存命中率大多數情況下保持在95~98%左右。然而,我們偶爾觀察到緩存命中率下降到70%-80%。我成功跟踪到這些下降是由於清理活動引起的。每當進行清理活動時,我們就會看到緩存命中率下降到70-80%。
I can't find a direct statement in any documentation that says "yes, vacuum activity evicts the buffer and so it causes the buffer cache hit ratio to drop significantly". The best I've managed is to find an explanation for how vacuuming works, and in the pseudocode it says that "it will scan all pages to get dead tuples" which I assume will cause these pages to load to the buffer cache and fill it with maybe not so relevant data, ultimately causing the hit ratio to suffer.
我找不到任何文件中明確說明“是的,清理活動會逐出緩存,因此會導致緩存命中率顯著下降”的語句。我所能找到的最好的解釋是找到清理操作的工作原理,在伪代码中它說“它將掃描所有頁面以獲取無效元組”,我認為這將導致這些頁面加載到緩存中並填充它,最終導致命中率下降。
Am I on the right path?
我走在正確的道路上嗎?
What are references on this relation between vacuum activity and the drop in buffer cache hit ratio?
關於清理活動和緩存命中率下降之間的關係,有哪些參考資料?
Vacuum documentation in official PostgreSQL documentation has no mention of its impact on the buffer cache.
官方PostgreSQL文檔中的清理文檔並未提到其對緩存的影響。
英文:
Most of the time, our PostgreSQL (version 13.8, AWS Aurora, PostgreSQL compatible) database's buffer cache hit ratio has been somewhere around 95~98%. However, we have been observing an occasional dip in the buffer cache hit ratio to 70%-80%. I managed to track the occurrences of these dips to vacuum activity. Whenever there's vacuum activity, we see the buffer cache hit ratio dip to 70-80%.
I can't find a direct statement in any documentation that says "yes, vacuum activity evicts the buffer and so it causes the buffer cache hit ratio to drop significantly". The best I've managed is to find an explanation for how vacuuming works, and in the pseudocode it says that "it will scan all pages to get dead tuples" which I assume will cause these pages to load to the buffer cache and fill it with maybe not so relevant data, ultimately causing the hit ratio to suffer.
Am I on the right path?
What are references on this relation between vacuum activity and the drop in buffer cache hit ratio?
Vacuum documentation in official PostgreSQL documentation has no mention of its impact on the buffer cache.
答案1
得分: 3
缓存命中率下降当数据库读取了大量未缓存的页面时。这正是 VACUUM
所做的,所以你观察到的并不令人意外。不要担心。
人们往往高估了缓存命中率的相关性。在必要时进行一些I/O并没有什么不好。
英文:
The cache hit ratio drops when the database reads lots of pages that are not cached. That's exactly what VACUUM
does, so what you observe is not very surprising. Don't worry.
People tend to overestimate the relevance of the cache hit ratio. There is nothing evil about doing some I/O when necessary.
答案2
得分: 3
VACUUM会使用环形缓冲区访问策略,这可以防止它驱逐很多其他页面,因为它更倾向于驱逐自己最近的页面。但VACUUM本身可能需要访问大量的冷页面,这当然需要读取。因此,VACUUM可能会导致全局命中率下降,不是因为它导致其他进程出现页面缺失,而是因为VACUUM本身出现了页面缺失。
英文:
VACUUM will use a ring buffer access strategy which prevents it from evicting very many other pages, as it preferentially evicts its own recent pages. But the VACUUM may itself need to visit a large number of cold pages, which will of course need to be read. So the VACUUM can cause the global hit rate to drop not because it causes other processes to have pages misses, but because the vacuum itself has page misses.
答案3
得分: 0
以下是已翻译的内容:
在PostgreSQL中有一些有益的维护活动和Aurora中的功能,这些活动和功能会产生额外的I/O,就像您所看到的那样。如果担心会产生额外的费用(因为Aurora按百万I/O操作计费),新的I/O优化配置可以缓解这种担忧:
https://aws.amazon.com/about-aws/whats-new/2023/05/amazon-aurora-i-o-optimized/
简而言之 - I/O优化设置提高了实例小时和存储的成本,但将I/O费用归零。因此,如果I/O费用占账单的重要部分,这可以是一项节省成本的措施。
英文:
There are some beneficial maintenance activities in PostgreSQL and features in Aurora that have the side effect of producing extra I/O like you saw. If there's a concern with extra cost (because Aurora charges per million I/O operations), the new I/O-optimized configuration can be a way to alleviate that concern:
https://aws.amazon.com/about-aws/whats-new/2023/05/amazon-aurora-i-o-optimized/
TL;DR - the I/O-optimized setting boosts the cost for instance hours and storage, but zeroes out the I/O charges. So if the I/O cost is a substantial part of the bill, it can be a cost-saving measure.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论