PostgreSQL bgwriter,walwriter,backend process 写磁盘的实时监控

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 标签PostgreSQL ,背景数据库有两大块buffer,wal buffer和shared buffer。wal buffer是预写日志缓冲区。shared buffer是数据页缓冲区。

标签

PostgreSQL ,


背景

数据库有两大块buffer,wal buffer和shared buffer。

wal buffer是预写日志缓冲区。

shared buffer是数据页缓冲区。

wal writer进程负责将wal buffer缓冲区的数据写入WAL FILE中。

background writer进程负责将shared buffer缓冲区的数据写入DATA FILE中。

如果写入量非常大,wal writer和background writer进程不足以满足系统负载时,用户进程(backend process)也会参与将BUFFER写到FILE的工作。

可以通过系统视图统计bgwriter,walwriter,backend process 写磁盘的实时指标。

1、pg_stat_bgwriter.buffers_clean bgwriter 每秒write多少shared buffer到disk(write-异步系统调用) , 说明了脏页产生较快,但是不影响业务。

2、pg_stat_bgwriter.buffers_backend backend process 每秒wirte多少shared buffer到disk(write-异步系统调用) , 说明产生脏页较快,并且bgwriter或checkpointer写脏页已经赶不上产生脏页的速度了,对业务开始有影响。

3、walwriter 每秒write多少wal buffer到disk(write-异步系统调用)

4、pg_stat_bgwriter.buffers_alloc 每秒分配多少新的shared buffer,说明了从磁盘读的频繁程度。

5、其他指标,参考pg_stat_bgwriter 视图的介绍

系统视图

1、pg_stat_bgwriter

https://www.postgresql.org/docs/11/monitoring-stats.html#MONITORING-STATS-VIEWS

postgres=# \d pg_stat_bgwriter   
                        View "pg_catalog.pg_stat_bgwriter"  
        Column         |           Type           | Collation | Nullable | Default   
-----------------------+--------------------------+-----------+----------+---------  
 checkpoints_timed     | bigint                   |           |          |   
 checkpoints_req       | bigint                   |           |          |   
 checkpoint_write_time | double precision         |           |          |   
 checkpoint_sync_time  | double precision         |           |          |   
 buffers_checkpoint    | bigint                   |           |          |   
 buffers_clean         | bigint                   |           |          |   
 maxwritten_clean      | bigint                   |           |          |   
 buffers_backend       | bigint                   |           |          |   
 buffers_backend_fsync | bigint                   |           |          |   
 buffers_alloc         | bigint                   |           |          |   
 stats_reset           | timestamp with time zone |           |          |   

2、检测wal写入量的函数

pg_current_wal_lsn(),查看当前的WAL LSN位点。

pg_wal_lsn_diff(lsn,lsn),计算两个LSN位点之间有多少字节。

例子

配置

shared_buffers = 3GB    
bgwriter_delay = 10ms    
bgwriter_lru_maxpages = 1000    
bgwriter_lru_multiplier = 10.0    
wal_writer_delay = 10ms   

压测

pgbench -i -s 1000  
  
pgbench -M prepared -n -r -P 1 -c 32 -j 32 -T 120000  

监测

1、bgwriter 每秒write多少shared buffer到disk(write-异步系统调用)

postgres=# select buffers_clean*8/1024||' MB' bg from pg_stat_bgwriter;  
    bg       
-----------  
 654155 MB  
(1 row)  
  
postgres=# \watch 1  
Sun 25 Nov 2018 12:34:25 PM CST (every 1s)  
  
    bg       
-----------  
 655538 MB  
(1 row)  
  
Sun 25 Nov 2018 12:34:26 PM CST (every 1s)  
  
    bg       
-----------  
 655842 MB  
(1 row)  
  
Sun 25 Nov 2018 12:34:27 PM CST (every 1s)  
  
    bg       
-----------  
 656139 MB  
(1 row)  
  
Sun 25 Nov 2018 12:34:28 PM CST (every 1s)  
  
    bg       
-----------  
 656444 MB  
(1 row)  

2、backend process 每秒wirte多少shared buffer到disk(write-异步系统调用)

postgres=# select buffers_backend*8/1024||' MB' bg from pg_stat_bgwriter;  
     bg       
------------  
 1008428 MB  
(1 row)  
  
postgres=# \watch 1  
Sun 25 Nov 2018 12:35:01 PM CST (every 1s)  
  
     bg       
------------  
 1009188 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:02 PM CST (every 1s)  
  
     bg       
------------  
 1009188 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:03 PM CST (every 1s)  
  
     bg       
------------  
 1009188 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:04 PM CST (every 1s)  
  
     bg       
------------  
 1009926 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:05 PM CST (every 1s)  
  
     bg       
------------  
 1009926 MB  
(1 row)  

3、walwriter 每秒write多少wal buffer到disk(write-异步系统调用)

postgres=# with a as (select pg_current_wal_lsn() lsn) select pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), lsn)) from a, pg_sleep(1);  
 pg_size_pretty   
----------------  
 31 MB  
(1 row)  
  
postgres=# \watch 0.001  
Sun 25 Nov 2018 12:35:25 PM CST (every 0.001s)  
  
 pg_size_pretty   
----------------  
 30 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:26 PM CST (every 0.001s)  
  
 pg_size_pretty   
----------------  
 31 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:27 PM CST (every 0.001s)  
  
 pg_size_pretty   
----------------  
 30 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:28 PM CST (every 0.001s)  
  
 pg_size_pretty   
----------------  
 31 MB  
(1 row)  
  

4、每秒分配多少新的shared buffer

postgres=# select buffers_alloc*8/1024||' MB' bg from pg_stat_bgwriter;  
     bg       
------------  
 2001145 MB  
(1 row)  
  
postgres=# \watch 1  
Sun 25 Nov 2018 12:35:57 PM CST (every 1s)  
  
     bg       
------------  
 2003212 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:58 PM CST (every 1s)  
  
     bg       
------------  
 2003979 MB  
(1 row)  
  
Sun 25 Nov 2018 12:35:59 PM CST (every 1s)  
  
     bg       
------------  
 2004769 MB  
(1 row)  
  
Sun 25 Nov 2018 12:36:00 PM CST (every 1s)  
  
     bg       
------------  
 2005554 MB  
(1 row)  
  
Sun 25 Nov 2018 12:36:01 PM CST (every 1s)  
  
     bg       
------------  
 2006329 MB  
(1 row)  

对比iotop与SQL监测数据是否一致

对比IOTOP的结果,以上统计方法,得到的结果与IOTOP一致。

otal DISK READ :       0.00 B/s | Total DISK WRITE :     654.63 M/s  
Actual DISK READ:       0.00 B/s | Actual DISK WRITE:     659.74 M/s  
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                                                                                                                                                         
 6438 be/4 postgres    0.00 B/s   30.98 M/s  0.00 %  1.01 % postgres: walwriter  
 6494 be/4 postgres    0.00 B/s   10.50 M/s  0.00 %  0.17 % postgres: postgres postgres [local] idle in transaction  
 6513 be/4 postgres    0.00 B/s   10.33 M/s  0.00 %  0.17 % postgres: postgres postgres [local] UPDATE               
 6496 be/4 postgres    0.00 B/s   10.52 M/s  0.00 %  0.17 % postgres: postgres postgres [local] UPDATE               
 6495 be/4 postgres    0.00 B/s   10.48 M/s  0.00 %  0.17 % postgres: postgres postgres [local] COMMIT               
 6509 be/4 postgres    0.00 B/s   10.41 M/s  0.00 %  0.16 % postgres: postgres postgres [local] idle in transaction  
 6491 be/4 postgres    0.00 B/s   10.75 M/s  0.00 %  0.16 % postgres: postgres postgres [local] COMMIT               
 6522 be/4 postgres    0.00 B/s   10.66 M/s  0.00 %  0.16 % postgres: postgres postgres [local] UPDATEn transaction  
 6505 be/4 postgres    0.00 B/s   10.66 M/s  0.00 %  0.16 % postgres: postgres postgres [local] COMMIT               
 6501 be/4 postgres    0.00 B/s   11.50 M/s  0.00 %  0.16 % postgres: postgres postgres [local] UPDATE               
 6507 be/4 postgres    0.00 B/s    9.95 M/s  0.00 %  0.15 % postgres: postgres postgres [local] UPDATE               
 6503 be/4 postgres    0.00 B/s    9.39 M/s  0.00 %  0.15 % postgres: postgres postgres [local] COMMIT               
 6493 be/4 postgres    0.00 B/s    9.48 M/s  0.00 %  0.15 % postgres: postgres postgres [local] idle in transaction  
 6523 be/4 postgres    0.00 B/s   11.36 M/s  0.00 %  0.15 % postgres: postgres postgres [local] UPDATEn transaction  
 6500 be/4 postgres    0.00 B/s   10.24 M/s  0.00 %  0.15 % postgres: postgres postgres [local] COMMIT               
 6498 be/4 postgres    0.00 B/s   10.45 M/s  0.00 %  0.15 % postgres: postgres postgres [local] idle in transaction  
 6519 be/4 postgres    0.00 B/s   10.66 M/s  0.00 %  0.15 % postgres: postgres postgres [local] idle in transaction  
 6508 be/4 postgres    0.00 B/s   10.24 M/s  0.00 %  0.15 % postgres: postgres postgres [local] idle                 
 6510 be/4 postgres    0.00 B/s   10.13 M/s  0.00 %  0.15 % postgres: postgres postgres [local] BINDTE               
 6504 be/4 postgres    0.00 B/s    9.61 M/s  0.00 %  0.15 % postgres: postgres postgres [local] COMMIT               
 6520 be/4 postgres    0.00 B/s   11.16 M/s  0.00 %  0.14 % postgres: postgres postgres [local] UPDATE               
 6511 be/4 postgres    0.00 B/s   10.21 M/s  0.00 %  0.14 % postgres: postgres postgres [local] BINDTE               
 6499 be/4 postgres    0.00 B/s    9.81 M/s  0.00 %  0.14 % postgres: postgres postgres [local] INSERT               
 6517 be/4 postgres    0.00 B/s   11.31 M/s  0.00 %  0.14 % postgres: postgres postgres [local] BIND                 
 6497 be/4 postgres    0.00 B/s    9.59 M/s  0.00 %  0.14 % postgres: postgres postgres [local] idle in transaction  
 6516 be/4 postgres    0.00 B/s    9.93 M/s  0.00 %  0.14 % postgres: postgres postgres [local] idle in transaction  
 6514 be/4 postgres    0.00 B/s   10.50 M/s  0.00 %  0.14 % postgres: postgres postgres [local] BIND                 
 6521 be/4 postgres    0.00 B/s   10.58 M/s  0.00 %  0.13 % postgres: postgres postgres [local] BIND                 
 6515 be/4 postgres    0.00 B/s   10.42 M/s  0.00 %  0.13 % postgres: postgres postgres [local] idle in transaction  
 6518 be/4 postgres    0.00 B/s    9.93 M/s  0.00 %  0.13 % postgres: postgres postgres [local] UPDATE               
 6502 be/4 postgres    0.00 B/s    9.63 M/s  0.00 %  0.12 % postgres: postgres postgres [local] COMMIT               
 6506 be/4 postgres    0.00 B/s   10.11 M/s  0.00 %  0.12 % postgres: postgres postgres [local] UPDATE               
 6492 be/4 postgres    0.00 B/s   10.52 M/s  0.00 %  0.11 % postgres: postgres postgres [local] BIND                 
 6437 be/4 postgres    0.00 B/s  292.30 M/s  0.00 %  0.01 % postgres: background writer  

参考

man write

https://www.postgresql.org/docs/11/monitoring-stats.html#MONITORING-STATS-VIEWS

《[未完待续] PostgreSQL 一键诊断项 - 珍藏级》

《PostgreSQL 实时健康监控 大屏 - 低频指标 - 珍藏级》

《PostgreSQL 实时健康监控 大屏 - 高频指标(服务器) - 珍藏级》

《PostgreSQL 实时健康监控 大屏 - 高频指标 - 珍藏级》

man iotop

《PostgreSQL 数据库巡检》

《PostgreSQL AWR报告(for 阿里云ApsaraDB PgSQL)》

《如何生成和阅读EnterpriseDB (PPAS(Oracle 兼容版)) AWR诊断报告》

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
SQL 监控 关系型数据库
21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控|学习笔记(三)
快速学习21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控
254 0
21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控|学习笔记(三)
|
SQL 分布式计算 并行计算
PostgreSQL 并行计算解说 之26 - parallel gather | gathermerge - enable leader worker process
标签 PostgreSQL , cpu 并行 , smp 并行 , 并行计算 , gpu 并行 , 并行过程支持 背景 PostgreSQL 11 优化器已经支持了非常多场合的并行。简单估计,已支持27余种场景的并行计算。 parallel seq scan parallel index scan parallel index only scan
493 0
|
数据采集 监控 关系型数据库
|
27天前
|
关系型数据库 分布式数据库 数据库
成都晨云信息技术完成阿里云PolarDB数据库产品生态集成认证
近日,成都晨云信息技术有限责任公司(以下简称晨云信息)与阿里云PolarDB PostgreSQL版数据库产品展开产品集成认证。测试结果表明,晨云信息旗下晨云-站群管理系统(V1.0)与阿里云以下产品:开源云原生数据库PolarDB PostgreSQL版(V11),完全满足产品兼容认证要求,兼容性良好,系统运行稳定。
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB常见问题之数据库不能自己减少节点如何解决
PolarDB是阿里云推出的下一代关系型数据库,具有高性能、高可用性和弹性伸缩能力,适用于大规模数据处理场景。本汇总囊括了PolarDB使用中用户可能遭遇的一系列常见问题及解答,旨在为数据库管理员和开发者提供全面的问题指导,确保数据库平稳运行和优化使用体验。
|
1月前
|
缓存 关系型数据库 分布式数据库
PolarDB常见问题之数据库cpu突然飙高如何解决
PolarDB是阿里云推出的下一代关系型数据库,具有高性能、高可用性和弹性伸缩能力,适用于大规模数据处理场景。本汇总囊括了PolarDB使用中用户可能遭遇的一系列常见问题及解答,旨在为数据库管理员和开发者提供全面的问题指导,确保数据库平稳运行和优化使用体验。
|
2月前
|
关系型数据库 分布式数据库 数据库
阿里云PolarDB登顶2024中国数据库流行榜:技术实力与开发者影响力
近日,阿里云旗下的自研云原生数据库PolarDB在2024年中国数据库流行度排行榜中夺冠,并刷新了榜单总分纪录,这一成就引起了技术圈的广泛关注。这一成就源于PolarDB在数据库技术上的突破与创新,以及对开发者和用户的实际需求的深入了解体会。那么本文就来分享一下关于数据库流行度排行榜的影响力以及对数据库选型的影响,讨论PolarDB登顶的关键因素,以及PolarDB“三层分离”新版本对开发者使用数据库的影响。
74 3
阿里云PolarDB登顶2024中国数据库流行榜:技术实力与开发者影响力
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB PostgreSQL版:Oracle兼容的高性能数据库
PolarDB PostgreSQL版是一款高性能的数据库,具有与Oracle兼容的特性。它采用了分布式架构,可以轻松处理大量的数据,同时还支持多种数据类型和函数,具有高可用性和可扩展性。它还提供了丰富的管理工具和性能优化功能,为企业提供了可靠的数据存储和处理解决方案。PolarDB PostgreSQL版在数据库领域具有很高的竞争力,可以满足各种企业的需求。
|
2天前
|
关系型数据库 OLAP 分布式数据库
「杭州*康恩贝」4月26日PolarDB开源数据库沙龙,开启报名!
4月26日周五,PolarDB开源社区联合康恩贝将共同举办开源数据库技术沙龙,本次沙龙我们邀请了众多数据库领域的专家,期待大家的参与!
「杭州*康恩贝」4月26日PolarDB开源数据库沙龙,开启报名!

相关产品

  • 云原生数据库 PolarDB