pgmonitor

面向外部采集器的指标视图与后台刷新工作进程

概览

扩展包名版本分类许可证语言
pgmonitor2.2.0STATApache-2.0C
ID扩展名BinLibLoadCreateTrustReloc模式
6070pgmonitor-
相关扩展pgnodemx system_stats pg_stat_monitor pg_profile

Metric objects work without preloading; the optional background worker requires shared_preload_libraries=pgmonitor_bgw.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY2.2.01817161514pgmonitor-
RPMPIGSTY2.2.01817161514pgmonitor_$v-
DEBPIGSTY2.2.01817161514postgresql-$v-pgmonitor-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
d13.aarch64
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
u22.x86_64
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
u22.aarch64
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
u24.x86_64
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
u24.aarch64
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
PIGSTY 2.2.0
u26.x86_64
u26.aarch64

构建

您可以使用 pig build 命令构建 pgmonitor 扩展的 RPM / DEB 包:

pig build pkg pgmonitor         # 构建 RPM / DEB 包

安装

您可以直接安装 pgmonitor 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install pgmonitor;          # 当前活跃 PG 版本安装
pig ext install -y pgmonitor -v 18  # PG 18
pig ext install -y pgmonitor -v 17  # PG 17
pig ext install -y pgmonitor -v 16  # PG 16
pig ext install -y pgmonitor -v 15  # PG 15
pig ext install -y pgmonitor -v 14  # PG 14
dnf install -y pgmonitor_18       # PG 18
dnf install -y pgmonitor_17       # PG 17
dnf install -y pgmonitor_16       # PG 16
dnf install -y pgmonitor_15       # PG 15
dnf install -y pgmonitor_14       # PG 14
apt install -y postgresql-18-pgmonitor   # PG 18
apt install -y postgresql-17-pgmonitor   # PG 17
apt install -y postgresql-16-pgmonitor   # PG 16
apt install -y postgresql-15-pgmonitor   # PG 15
apt install -y postgresql-14-pgmonitor   # PG 14

预加载配置

shared_preload_libraries = 'pgmonitor_bgw';

创建扩展

CREATE EXTENSION pgmonitor;

用法

来源:

pgmonitor 通过一组精心挑选的视图、物化视图和表向外部收集器暴露 PostgreSQL 监控指标。其 SQL 指标无需后台工作进程即可使用;可选的 pgmonitor_bgw 后台工作进程会定期刷新物化数据。

安装扩展

创建一个专用模式并在此安装 pgmonitor:

CREATE SCHEMA pgmonitor_ext;
CREATE EXTENSION pgmonitor SCHEMA pgmonitor_ext;

仅授予收集器所需的访问权限,以访问指标对象。某些底层的 PostgreSQL 统计信息仍受内置角色和行可见性规则的约束。

收集指标

外部代理可以选择由扩展配置表描述的活动对象:

SELECT *
FROM pgmonitor_ext.metric_views
WHERE active;

SELECT *
FROM pgmonitor_ext.metric_matviews
WHERE active;

SELECT *
FROM pgmonitor_ext.metric_tables
WHERE active;

这些表描述了指标名称、激活状态、作用范围和刷新间隔。查询安装的定义,而不是假设每个 PostgreSQL 版本都启用了所有指标。

指标表面包括活动情况、数据库和表统计信息、锁、复制、WAL 和归档状态、真空进度、配置设置、检查点以及当其依赖项可用时的扩展特定视图。

手动刷新物化指标

无需后台工作进程,可以调用为指定模式和指标配置的刷新过程:

CALL pgmonitor_ext.refresh_metrics(
  'pgmonitor_ext',
  'pg_stat_statements'
);

使用 metric_matviews 返回的名称;不要假设示例指标已安装或处于活动状态。该扩展保留了一个兼容性旧版刷新函数,但新的集成应使用文档中的过程。

可选后台工作进程

要在 PostgreSQL 内部安排刷新:

shared_preload_libraries = 'pgmonitor_bgw'
pgmonitor_bgw.dbname = 'postgres,app'
pgmonitor_bgw.role = 'postgres'
pgmonitor_bgw.interval = 30

更改 shared_preload_libraries 后重启 PostgreSQL。pgmonitor_bgw.dbname 是必需的,列出了要维护的数据库。上游 v2.2 当前要求工作进程角色为超级用户;使用最窄控制的角色,并保护其凭据和设置。

对象索引

  • metric_views: 直接查询的指标视图及其收集元数据。
  • metric_matviews: 物化指标及刷新间隔。
  • metric_tables: 表支持的指标及维护元数据。
  • refresh_metrics(schema, name): 为一个配置的指标调用刷新过程。
  • pgmonitor_bgw.dbname: 由可选工作进程处理的数据库。
  • pgmonitor_bgw.role: 用于刷新工作的角色。
  • pgmonitor_bgw.interval: 工作循环间隔(秒)。

版本 2.2 及注意事项

版本 2.2 移除了设置校验指标,修复了 PostgreSQL 13 上的旧版刷新路径,并减少了常规日志噪音。

  • 指标查询会增加共享统计信息、目录和扩展对象的负载。根据测量的成本设置收集间隔。
  • 健康的收集器连接并不能证明物化视图是新鲜的;监控它们的时间戳和工作进程日志。
  • 该扩展提供数据库指标,而不是主机、文件系统或进程指标。
  • 安装 pgmonitor 不会自动配置 Prometheus、导出程序、仪表板或警报规则。