跳转到主要内容

pg_rusage

通过显式重置与输出调用测量当前后端的 CPU 消耗

概览

扩展包名版本分类许可证语言
pg_rusage1.0STATPostgreSQLC
ID扩展名BinLibLoadCreateTrustReloc模式
6230pg_rusage否是否是否是-

pg_rusage_print() emits the current backend measurement as a WARNING and returns void. No preload; PostgreSQL 14-18 verified in PGSTY builds; upstream declares no major-version matrix.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY1.01817161514pg_rusage-
RPMPIGSTY1.01817161514pg_rusage_$v-
DEBPIGSTY1.01817161514postgresql-$v-pg-rusage-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u26.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u26.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

构建

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

pig build pkg pg_rusage         # 构建 RPM / DEB 包

安装

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

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

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

安装
pig install pg_rusage;          # 当前活跃 PG 版本安装
pig
pig ext install -y pg_rusage -v 18  # PG 18
pig ext install -y pg_rusage -v 17  # PG 17
pig ext install -y pg_rusage -v 16  # PG 16
pig ext install -y pg_rusage -v 15  # PG 15
pig ext install -y pg_rusage -v 14  # PG 14
dnf
dnf install -y pg_rusage_18       # PG 18
dnf install -y pg_rusage_17       # PG 17
dnf install -y pg_rusage_16       # PG 16
dnf install -y pg_rusage_15       # PG 15
dnf install -y pg_rusage_14       # PG 14
apt
apt install -y postgresql-18-pg-rusage   # PG 18
apt install -y postgresql-17-pg-rusage   # PG 17
apt install -y postgresql-16-pg-rusage   # PG 16
apt install -y postgresql-15-pg-rusage   # PG 15
apt install -y postgresql-14-pg-rusage   # PG 14

创建扩展:

CREATE EXTENSION pg_rusage;

用法

来源:

pg_rusage — 这个模块是一个 PostgreSQL 扩展,可以启用 CPU 测量,包含一个用于启用测量的 SQL 函数和一个用于禁用测量的 SQL 函数。在禁用时,现有的累积结果将会显示出来。在收集或解释相应的 PostgreSQL 统计信息时使用它。请使用上述链接的上游固定版本作为 API 边界,并在目标 PostgreSQL 构建中进行测试。

核心工作流

CREATE EXTENSION pg_rusage;

在目标数据库中安装扩展,当可用时运行上游示例中的最小示例,并在将其集成到应用程序 SQL 中之前验证安装的版本和返回值。

重要对象

  • pg_rusage_print() 是一个扩展函数,返回 void。
  • pg_rusage_reset() 是一个扩展函数,返回 void。

要求与注意事项

  • 审查后的控制文件声明默认版本为 1.0。
  • 控制文件将扩展标记为可重定位。
  • 在生产使用前,请确认权限、支持的 PostgreSQL 版本、升级行为和失败情况,与固定源进行比对。

这个页面对您有帮助吗?