【重新发现PostgreSQL之美】- 50 一粒老鼠屎

简介: 大家好,这里是重新发现PostgreSQL之美 - 50 一粒老鼠屎

背景


场景:

  • 在正常业务使用期间, DBA、开发者、分析师在数据库中跑大查询, 某些大表采用了全表扫描.

挑战:

  • 大表的全表扫描会占用buffer pool, 从而将shared buffer中的热数据挤出去, 导致其他业务的SQL变慢, 严重的导致雪崩.

PG 解决方案:

除了全表扫描, PG的bulk - write, vacuum都有类似机制:

bulk - write 16MB ring buffer

COPY FROM command.

CREATE TABLE AS command.

CREATE MATERIALIZED VIEW or REFRESH MATERIALIZED VIEW command.

ALTER TABLE command.

vacuum 256KB ring buffer.

When reading or writing a huge table, PostgreSQL uses a ring buffer rather than the buffer pool. The ring buffer is a small and temporary buffer area. When any condition listed below is met, a ring buffer is allocated to shared memory:

Bulk-reading

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.

The allocated ring buffer is released immediately after use.

The benefit of the ring buffer is obvious. If a backend process reads a huge table without using a ring buffer, all stored pages in the buffer pool are removed (kicked out); therefore, the cache hit ratio decreases. The ring buffer avoids this issue.

Why the default ring buffer size for bulk-reading and vacuum processing is 256 KB?

Why 256 KB? The answer is explained in the README located under the buffer manager's source directory.

For sequential scans, a 256 KB ring is used. That's small enough to fit in L2 cache, which makes transferring pages from OS cache to shared buffer cache efficient. Even less would often be enough, but the ring must be big enough to accommodate all pages in the scan that are pinned concurrently. (snip)



相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
Linux 虚拟化
VMware虚拟机 用共享文件夹方式 与主机传输文件(图文)
VMware虚拟机 用共享文件夹方式 与主机传输文件(图文)
VMware虚拟机 用共享文件夹方式 与主机传输文件(图文)
|
6月前
|
人工智能 API 数据安全/隐私保护
2026年搭建OpenClaw “AI Agent 赚钱机器“指南:5个小白友好型睡后收入方案(附实操代码)
2026年,AI Agent领域正迎来一场“财富转移”——数据显示,67%的独立开发者已通过OpenClaw(原ClawdBot/Moltbot)产生稳定收入,34%的人在第一个月就突破四位数美元营收。这款开源AI助手的核心优势在于“自动化执行+技能扩展”,能7×24小时处理线索抓取、内容创作、客服响应等重复性工作,让普通人也能轻松搭建“AI赚钱机器”。
7305 4
|
Oracle Cloud Native 关系型数据库
Oracle Linux 9.6 正式版发布 - Oracle 提供支持 RHEL 兼容发行版
Oracle Linux 9.6 正式版发布 - Oracle 提供支持 RHEL 兼容发行版
597 0
Oracle Linux 9.6 正式版发布 - Oracle 提供支持 RHEL 兼容发行版
|
Oracle 关系型数据库 大数据
Oracle 19c Centos7 静默安装记录整理 1
Oracle 19c Centos7 静默安装记录整理
|
安全 数据库 数据安全/隐私保护
数据库 变更和版本控制管理工具 --Bytebase 安装部署
数据库 变更和版本控制管理工具 --Bytebase 安装部署
1470 0
|
存储 固态存储 关系型数据库
PostgreSQL核心操作之数据备份恢复
PostgreSQL核心操作之数据备份恢复
2136 0
|
监控 关系型数据库 数据库
RDS PostgreSQL内置连接池PgBouncer
2023年7月,阿里云RDS PostgreSQL支持内置数据库连接池PgBouncer,本篇文章从以下角度探讨PgBouncer:1. PgBouncer是什么;2. 应用场景 ;3. 性能对比;4. 如何使用;5. 总结
|
存储 关系型数据库 Linux
在Centos7环境下进行搭建postgresql-xl集群环境
在Centos7环境下进行搭建postgresql-xl集群环境
422 0
在Centos7环境下进行搭建postgresql-xl集群环境
|
Ubuntu Windows
virtualbox虚拟机环境搭建之二---Virtualbox主机与虚拟机设置文件共享
virtualbox虚拟机环境搭建之二---Virtualbox主机与虚拟机设置文件共享
1462 0