Skip to content

pg_rusage

Measure backend CPU usage between explicit reset and print calls

Overview

PackageVersionCategoryLicenseLanguage
pg_rusage1.0STATPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
6230pg_rusageNoYesNoYesNoYes-

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.

Version

TypeRepoVersionPG VerPackageDeps
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

Build

You can build the RPM / DEB packages for pg_rusage using pig build:

pig build pkg pg_rusage         # build RPM / DEB packages

Install

You can install pg_rusage directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

Install
pig install pg_rusage;          # Install for current active PG version
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:

CREATE EXTENSION pg_rusage;

Usage

Sources:

pg_rusage — This module is a PostgreSQL extension that can enable CPU measurements, with one SQL function to enable the measurement and one to disable it. When disabling, the existing accumulated results will show up. Use it when collecting or interpreting the corresponding PostgreSQL statistics. Use the pinned upstream revision linked above as the API boundary and test it on the target PostgreSQL build.

Core Workflow

CREATE EXTENSION pg_rusage;

Install the extension in the intended database, run the smallest upstream example above when available, and verify the installed version and returned values before integrating it into application SQL.

Important Objects

  • pg_rusage_print() is an extension function and returns void.
  • pg_rusage_reset() is an extension function and returns void.

Requirements and Caveats

  • The reviewed control file declares default version 1.0.
  • The control file marks the extension as relocatable.
  • Confirm privileges, supported PostgreSQL versions, upgrade behavior, and failure cases against the pinned source before production use.

Was this page helpful?