对PostgreSQL中NBuffers的理解

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

开始

看PostgreSQL 中  shared_buffers 的值 是  32MB

打印 src/backend/storage/buffer/bufmgr.c 中, NBuffers 的值:

结果:

复制代码
[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data
LOG:  database system was shut down at 2012-11-01 17:19:27 CST
NBuffers is: 4096
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
NBuffers is: 4096
......
复制代码

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

再看NBuffers 的资料:-B NBuffers 是可以作为 Postgres 运行时候的命令行参数的。

http://www.postgresql.org/docs/current/static/app-postgres.html

-B nbuffers

Sets the number of shared buffers for use by the server processes. The default value of this parameter is chosen automatically by initdb. Specifying this option is equivalent to setting the shared_buffers configuration parameter.

也就是说 NBuffers 和 Shared_Buffers 应该相同。

32MB是如何等于 4096的呢。

32MB=32*1024*1024=33554432 字节

4096页*8K/页=4096*8*1024=33554432字节。

看一下修改后会如何:

复制代码
[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data -B 8192
LOG:  database system was shut down at 2012-11-02 09:32:27 CST
NBuffers is: 8192
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
NBuffers is: 8192
NBuffers is: 8192
NBuffers is: 8192
复制代码
复制代码
[postgres@localhost bin]$ ./psql
psql (9.2.0)
Type "help" for help.

postgres=# show shared_buffers;
 shared_buffers 
----------------
 64MB
(1 row)

postgres=# 
复制代码

guc.c 中的代码,也可以论证其对应关系:

复制代码
/*                                    
 * We sometimes multiply the number of shared buffers by two without                                    
 * checking for overflow, so we mustn't allow more than INT_MAX / 2.                                    
 */                                    
{                                    
    {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,                                
        gettext_noop("Sets the number of shared memory buffers used by the server."),                            
        NULL,                            
        GUC_UNIT_BLOCKS                            
    },                                
    &NBuffers,                                
    1024, 16, INT_MAX / 2,                                
    NULL, NULL, NULL                                
},                                    
.....
复制代码





相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
5月前
|
关系型数据库 PostgreSQL
postgresql中geom处理
pgsql中的geom格式处理
67 0
|
7月前
|
SQL 存储 关系型数据库
PostgreSQL
PostgreSQL 是一款功能强大的开源关系型数据库管理系统,它支持 SQL(结构化查询语言)并提供了许多高级功能,如存储过程、视图、触发器、自定义数据类型等。PostgreSQL 适用于许多场景,如 Web 应用、数据仓库、科学计算等。
59 3
|
8月前
|
存储 关系型数据库 数据库连接
PostgreSQL很多优秀的书籍
PostgreSQL很多优秀的书籍
377 1
|
关系型数据库 大数据 数据库
PostgreSQL 11 小记
## 关于 PostgreSQL [PostgreSQL](https://en.wikipedia.org/wiki/PostgreSQL) 是世界上最先进的开源数据库。 PostgreSQL 最早可追溯到 1973 年,当时加州大学伯克利分校的两位科学家,[Michael Stonebraker](https://en.
5506 0
|
关系型数据库 PostgreSQL 存储
|
关系型数据库 PostgreSQL
|
关系型数据库 PostgreSQL SQL

热门文章

最新文章