Skip to content

pg_stat_sysinfo

Query host load, CPU, memory, swap, and disk statistics from PostgreSQL, with optional shared-memory caching.

pg_stat_sysinfo · Query host load, CPU, memory, swap, and disk statistics from PostgreSQL, with optional shared-memory caching.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100803pg_stat_sysinfopg_stat_sysinfo0.0.1STATMITRust

PostgreSQL · 14, 15

Usage

Sources:

pg_stat_sysinfo 0.0.1 is a pgrx system-metrics prototype. It reports load averages, CPU use, memory and swap capacity and use, and mounted-disk capacity. pg_stat_sysinfo_collect() samples synchronously; an optional background worker stores recent samples in a shared-memory ring buffer exposed through the pg_stat_sysinfo view.

Direct and cached collection

Direct collection does not require preloading:

CREATE EXTENSION pg_stat_sysinfo;

SELECT * FROM pg_stat_sysinfo_collect();

For cached collection, configure the library and interval, then restart PostgreSQL:

shared_preload_libraries = 'pg_stat_sysinfo.so'
pg_stat_sysinfo.interval = '1s'
SELECT metric, dimensions, at, value
FROM pg_stat_sysinfo
ORDER BY at DESC;

SELECT * FROM pg_stat_sysinfo_cache_summary();

The fixed cache is about 1280 KiB, so retention varies with the number of filesystems and collection interval. A configuration reload can change the interval and periodically refresh the disk list.

Visibility, overhead, and compatibility

Metrics reveal host load, memory, swap, filesystem mount names, and capacities. Review default function execution privileges and grant access only to monitoring roles. Direct calls refresh operating-system counters and may briefly wait for the system library’s minimum CPU sampling interval; aggressive polling adds backend and filesystem-enumeration work.

The reviewed Cargo features cover PostgreSQL 11 through 15 with pgrx 0.8.3, and the last code change is from 2023. There is no evidence for current majors or containers with unusual mount namespaces. Values are point-in-time host observations, not PostgreSQL attribution and not durable monitoring. Validate units, cgroup visibility, disk discovery, failover behavior, and sampling overhead, then export important metrics to a maintained monitoring system.

Table reader