PG性能采集分析工具之PoWA介绍

0    121    2

Tags:

👉 本文共约18156个字,系统预计阅读时间或需69分钟。

简介

PoWA--PostgreSQL 负载分析工具

本文主要介绍 PG 的一个性能采集和分析工具 PoWA 的部署方法和使用特点,该工具利用 PG 的扩展插件实现,其性能诊断分析能力比较接近 ORACLE AWR 报表功能。

PoWA是PostgreSQL 9.4及以后更新版本的性能工具,允许从各种Stats Extensions收集、聚合和清除多个 PostgreSQL 实例的统计信息,全称为PostgreSQL工作负载分析器(PostgreSQL Workload Analyzer)。

PoWA组成部分如下:

  1. PoWA-archivist是PostgreSQL的插件,收集其他插件获取到的性能统计数据。PoWA-archivist是PoWA的核心组件。其主要有如下2个部分:
    • 名为“powa”的管理功能扩展。
    • 名为“powa”的模块,可以选择作为后台工作程序运行,用以收集本地实例上的性能数据。
  2. PoWA-collector是在专用存储库服务器上,用于收集远程PostgreSQL实例性能指标的守护进程。
  3. PoWA-web是PoWA-collector收集到的性能指标的用户展示界面。
  4. 其它插件:安装于目标PostgreSQL数据库实例上的其他插件,其是性能指标数据的实际来源。
  5. PoWA:整个系统的总称。

除了pg_stat_statements、btree_gist、powa为必须的插件,PoWA还支持以下几个插件作为新能指标采集的扩展

  1. pg_qualstats:用于保存在WHERE语句和JOIN子句中发现的谓词的统计信息,powa 利用它来提供索引建议。

  2. pg_stat_kcache:收集有关文件系统层的实际读取和写入的统计信息,可以用于观察SQL花费多少cpu等。

  3. pg_wait_sampling:用于收集等待事件的采样统计信息,启用后它会收集如下两种统计信息:

    • 历史等待事件。它被实现为内存中的环形缓冲区,其中每个进程等待事件的样本都以给定的(可配置的)周期写入。因此,对于每个正在运行的进程,用户可以根据历史大小(可配置)查看一些最近的样本。假设有一个客户端定期读取此历史记录并将其转储到某个地方,则用户可以拥有连续的历史记录。

    • 等待分析,以内存hash表形式存在,表中存放每个进程和每个等待事件累积的样本,该表可以根据用户请求进行reset。假设有一个客户端定期转储并reset,用户可以统计一段时间内等待事件的详细。

  4. pg_track_settings:该插件提供了一个可定期调用的函数(pg_tracksettingssnapshot())。 在每次调用时,它将存储自上次调用以来更改的设置。

  5. Hypopg:类似MySQL虚拟索引。

  6. pg_stat_statements:用于SQL语句监控。

一些连接

文档:https://powa.readthedocs.io/en/latest/

GitHub地址:https://github.com/powa-team

https://github.com/powa-team/powa-archivist

https://github.com/powa-team/powa-web

cpu, io消耗监控
https://github.com/powa-team/pg_stat_kcache

where条件过滤性统计
https://github.com/powa-team/pg_qualstats

官网提供了一个公网的例子,可以在线查看。

部署架构简介

PoWA 4.0 之后的部署架构支持本地部署和远程部署。推荐用远程部署方式,部署架构图如下。
PG性能采集分析工具之PoWA介绍
在每个 PG 实例里启用插件,在独立的服务器上部署采集程序 PoWA collector 和主程序 PoWA web。
上面架构图用到的插件简介如下:

  • pg_stat_statements :记录指定 PG 实例上所有 SQL 的统计信息,具体数据在视图 pg_stat_statements 上。
  • pg_qualstats :采集 SQL 语句的 wherejoin 语句中的条件的统计信息。
  • pg_stat_kcache :采集主机系统指标的统计信息。
  • pg_wait_sampling :采集 SQL 语句的等待事件,并提供等待事件的汇总统计视图。
  • pg_track_settings :主要是跟踪实例的参数配置变化。

在生产环境中,我们要做的是竟可能避免单个PG的powa库中的数据量过大。但是我们又要存放一段时间的快照信息用于性能分析,这个类似于Oracle的AWR快照信息。

这个时候我们就需要专门创建一个单独的powa数据库用于存储各个pg采集过来的数据。所以生产环境中我们基本上采取的远程模式部署powa。

PG性能采集分析工具之PoWA介绍

远程模式示意图

数据库级性能指标

General Overview

图1 General Overview
PG性能采集分析工具之PoWA介绍

字段中文解释英文解释
Queries per sec每秒执行查询的次数。Number of time the query has been executed,per second
Runtime per sec每秒内执行查询的总耗时。Total duration of queries executed,per second
Avg runtime查询的平均耗时。Average query duration
字段中文解释英文解释
Total shared buffers hit命中共享缓冲区的数据量。Amount of data found in shared buffers
Total shared buffers miss未命中共享缓冲区的数据量。Amount of data found in OS cache or read from disk。

Database Objects

图2 Database Objects
PG性能采集分析工具之PoWA介绍

字段中文解释英文解释
Index scans ratio索引扫描/序列扫描的比率。Ratio of index scan / seq scan
Index scans每秒索引扫描次数。Number of index scan per second
Sequential scans每秒顺序扫描次数。Number of sequential scan per second
字段中文解释英文解释
Tuples inserted每秒插入的行数。Number of tuples inserted per second
Tuples updated每秒更新的行数。Number of tuples updated per second
Tuples HOT updated每秒更新(HOT)的行数。Number of tuples HOT updated per second
Tuples deleted每秒删除的行数。Number of tuples deleted per second
字段中文解释英文解释
# Vacuum每秒手动清理的次数。Number of vacuum per second
# Autovacuum每秒自动清理的次数。Number of autovacuum per second
# Analyze每秒手动分析的次数。Number of analyze per second
# Autoanalyze每秒自动分析的次数。Number of autoanalyze per second

Details for all databases

图3 Details for all databases
PG性能采集分析工具之PoWA介绍

字段注释
Query执行的SQL。
(Execution) #执行该SQL次数。
(Execution) Time执行该SQL总时间。
(Execution) Avg time执行该SQL平均时间。
(I/O Time) Read读I/O等待时间。
(I/O Time) Write写I/O等待时间。
(Blocks) Read磁盘读页面数。
(Blocks) Hit共享缓冲区命中页面数。
(Blocks) Dirtied脏页面数。
(Blocks) Written磁盘写页面数。
(Temp blocks) Read磁盘读临时页面数。
(Temp blocks) Write磁盘写临时页面数。

实例级性能指标

General Overview

图1 General Overview性能指标
PG性能采集分析工具之PoWA介绍

字段中文解释英文解释
Queries per sec每秒执行查询的次数。Number of time the query has been executed, per second
Runtime per sec每秒执行的查询的总持续时间。Total duration of queries executed, per second
Avg runtime平均查询时长。Average query duration
字段中文解释英文解释
Total hit在共享缓冲区中找到的数据量。Amount of data found in shared buffers
Total read在操作系统缓存中找到或从磁盘读取的数据量。Amount of data found in OS cache or read from disk

Background Writer

图2 Background Writer性能指标
PG性能采集分析工具之PoWA介绍

字段中文解释英文解释
of requested checkpoints已执行的请求检查点数。Number of requested checkpoints that have been performed
of scheduled checkpoints已执行的预定检查点数。Number of scheduled checkpoints that have been performed
字段中文解释英文解释
Buffers alloc分配的缓冲区数。Number of buffers allocated
Sync time文件同步到磁盘的检查点处理部分所花费的总时间(单位 : 毫秒)。Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds
Write time在将文件写入磁盘的检查点处理部分中花费的总时间(单位 : 毫秒)。Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds
字段中文解释英文解释
Maxwritten clean后台编写器因写入过多缓冲区而停止清理扫描的次数。Number of times the background writer stopped a cleaning scan because it had written too many buffers
Buffers clean后台写入器写入的缓冲区数。Number of buffers written by the background writer
字段中文解释英文解释
Buffers backend fsync后端必须执行自己的 fsync 调用的次数。Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)
Buffers backend后端直接写入的缓冲区数。Number of buffers written directly by a backend

Database Objects

图3 Database Objects性能指标
PG性能采集分析工具之PoWA介绍

字段中文解释英文解释
Index scans ratio索引扫描/序列扫描的比率。Ratio of index scan / seq scan
Index scans每秒索引扫描次数。Number of index scan per second
Sequential scans每秒顺序扫描次数。Number of sequential scan per second
字段中文解释英文解释
Tuples inserted每秒插入的行数。Number of tuples inserted per second
Tuples updated每秒更新的行数。Number of tuples updated per second
Tuples HOT updated每秒更新(HOT)。Number of tuples HOT updated per second
Tuples deleted每秒删除的行数。Number of tuples deleted per second
字段中文解释英文解释
# Vacuum每秒手动清理的次数。Number of vacuum per second
# Autovacuum每秒自动清理的次数。Number of autovacuum per second
# Analyze每秒手动分析的次数。Number of analyze per second
# Autoanalyze每秒自动分析的次数。Number of autoanalyze per second

Details for all databases

图4 Details for all databases性能指标
PG性能采集分析工具之PoWA介绍

字段注释
Database数据库名称。
#Calls执行SQL总数。
Runtime执行SQL总耗时。
Avg runtime执行SQL平均耗时。
Blocks read磁盘读取的页面数。
Blocks hit共享缓冲区命中的页面数。
Blocks dirtied脏页数。
Blocks written磁盘写页面数。
Temp Blocks written磁盘写临时页面数。
I/O timeI/O等待时间。

PoWA archivlist 部署介绍

参考:https://powa.readthedocs.io/en/latest/quickstart.html

简介
PoWA-archivlist 是 PoWA 项目的重要组件之一,它包含 2 个元素:

  • 扩展 powa ,包含一些管理用的函数。

  • 模块 powa ,可选,在后台运行,采集本地实例的性能。

安装方法:
建议使用 PGDG 软件源里的安装包安装。rpm包下载:https://download.postgresql.org/pub/repos/yum/14/redhat/rhel-7-x86_64/

在目标 PG 实例里创建数据库 powa 和相应的扩展。

也可以用下面方式自动创建依赖的扩展。

修改 PG 配置文件
安装完成后修改 postgresql.conf 里预加载的模块参数,需要重启 PG 实例才可以加载模块。

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!
PG性能采集分析工具之PoWA介绍后续精彩内容已被小麦苗无情隐藏,请输入验证码解锁本站所有文章!
验证码:
请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“DB宝”或者“www_xmmup_com”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复

嘿,我是小麦,需要帮助随时找我哦。
  • 18509239930
  • 个人微信

  • DB宝
  • 个人邮箱
  • 点击加入QQ群
  • 个人微店

  • 回到顶部