对PostgreSQL中bufmgr.c 中 bufs_to_lap的初步理解

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

开始,在代码中加入调试信息。无关部分设省略。

复制代码
bool                                
BgBufferSync(void)                                
{                                
    ……                                                            
    int            bufs_to_lap;                
    ……                            
    if (saved_info_valid)                            
    {
//added by gaojian
fprintf(stderr,"saved_info_valid true\n");
int32 passes_delta
= strategy_passes - prev_strategy_passes; strategy_delta = strategy_buf_id - prev_strategy_buf_id; strategy_delta += (long) passes_delta *NBuffers;
......
if ((int32) (next_passes - strategy_passes) > 0) {
fprintf(stderr,"next_pass > strategy_passes.\n");
/* we're one pass ahead of the strategy point */ bufs_to_lap = strategy_buf_id - next_to_clean; …… } else if (next_passes == strategy_passes && next_to_clean >= strategy_buf_id) {
fprintf(stderr,"next_passes == strategy_passes.\n");
/* on same pass, but ahead or at least not behind */ bufs_to_lap = NBuffers - (next_to_clean - strategy_buf_id); …… } else { fprintf(stderr,"we are behind.\n");
/* * We're behind, so skip forward to the strategy point and start * cleaning from there. */ next_to_clean = strategy_buf_id; next_passes = strategy_passes; bufs_to_lap = NBuffers; …… } } else {
fprintf(stderr,"saved_info_valid false\n"); …… bufs_to_lap
= NBuffers; } …… bufs_ahead = NBuffers - bufs_to_lap; …… num_to_scan = bufs_to_lap;
......
/* Execute the LRU scan */ while (num_to_scan > 0 && reusable_buffers < upcoming_alloc_est) { //added by gaojian fprintf(stderr,"num_to_scan is: %d \n",num_to_scan); int buffer_state = SyncOneBuffer(next_to_clean, true); if (++next_to_clean >= NBuffers) { next_to_clean = 0; elog(INFO,"------------------next_passes++.\n"); next_passes++; } num_to_scan--; …… } …… new_strategy_delta = bufs_to_lap - num_to_scan; new_recent_alloc = reusable_buffers - reusable_buffers_est; if (new_strategy_delta > 0 && new_recent_alloc > 0) { scans_per_alloc = (float) new_strategy_delta / (float) new_recent_alloc; smoothed_density += (scans_per_alloc - smoothed_density) / smoothing_samples; …… }
......
}
复制代码

运行的结果会如何呢? 

复制代码
[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data
LOG:  database system was shut down at 2012-11-02 13:51:46 CST
saved_info_valid false.
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
saved_info_valid true.
next_passes == strategy_passes.
saved_info_valid true.
next_passes == strategy_passes.
saved_info_valid true.
next_passes == strategy_passes.
saved_info_valid true.
next_passes == strategy_passes.
saved_info_valid true.
......
复制代码

也就是说,一开始  saved_info_valid 是 false, 后来经过一次运行后,其值才发生转变,变成 true。

而之后, next_passes == startegy_passes  (其实,一开始都是零)

结束






本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/11/02/2751104.html,如需转载请自行联系原作者

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