背景
1、産品的問題點
- PG 不支援繞過shared buffer的查詢和寫入
2、問題點背後涉及的技術原理
- PG 讀寫操作都要經過shared buffer , 某些特定場景除外: 《PostgreSQL shared buffer 管理機制》
- Bulk-reading (當表被全表掃描時, 隻有當表的大小超過四分之一shared buffer時, 才會使用ring buffer)
-
- When a relation whose size exceeds one-quarter of the buffer pool size (shared_buffers/4) is scanned. In this case, the ring buffer size is 256 KB.
- Bulk-writing
-
- When the SQL commands listed below are executed. In this case, the ring buffer size is 16 MB.
- COPY FROM command.
- CREATE TABLE AS command.
- CREATE MATERIALIZED VIEW or REFRESH MATERIALIZED VIEW command.
- ALTER TABLE command.
- Vacuum-processing
-
- When an autovacuum performs a vacuum processing. In this case, the ring buffer size is 256 KB.
3、這個問題将影響哪些行業以及業務場景
- 通用
4、會導緻什麼問題?
- 大表查詢, 寫入大量資料(insert into)時可能導緻shared buffer裡面的熱資料被擠出去. 業務高峰期可能帶來RT抖動, 影響業務體驗, 嚴重的甚至雪崩.
5、業務上應該如何避免這個坑
- 避免高峰期全表掃描小于四分之一shared buffer的大表
6、業務上避免這個坑犧牲了什麼, 會引入什麼新的問題
- 無法完全杜絕
7、資料庫未來産品疊代如何修複這個坑
- 期望核心支援繞過shared buffer的查詢和寫入文法, 或通過會話GUC參數可以控制. 避免大表查詢對熱資料的影響.