跳转到主要内容

pg_proctab

PostgreSQL extension to access the OS process table

pgnodemx : PostgreSQL extension to access the OS process table

Overview

ID Extension Package Version Category License Language
6460 pg_proctab pgnodemx 2.0.1 STAT Apache-2.0 SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d-r No No No Yes yes no
Relationships
Requires pgnodemx
See Also system_stats pg_stat_kcache pgmeminfo
Siblings pgnodemx
Compatibility stub; PGDG RPM incomplete.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 2.0.1 18 17 16 15 14 pgnodemx pgnodemx
RPM PIGSTY 2.0.1 18 17 16 15 14 pgnodemx_$v -
DEB PGDG 2.0.1 18 17 16 15 14 postgresql-$v-pgnodemx -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1
el8.aarch64 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1
el9.x86_64 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1
el9.aarch64 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1
el10.x86_64 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1
el10.aarch64 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1 PIGSTY 2.0.1
d12.x86_64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
d12.aarch64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
d13.x86_64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
d13.aarch64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
u22.x86_64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
u22.aarch64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
u24.x86_64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
u24.aarch64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
u26.x86_64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1
u26.aarch64 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1 PGDG 2.0.1

Source

pig build pkg pgnodemx;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pgnodemx;		# install via package name, for the active PG version
pig install pg_proctab;		# install by extension name, for the current active PG version

pig install pg_proctab -v 18;   # install for PG 18
pig install pg_proctab -v 17;   # install for PG 17
pig install pg_proctab -v 16;   # install for PG 16
pig install pg_proctab -v 15;   # install for PG 15
pig install pg_proctab -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_proctab CASCADE; -- requires pgnodemx

Usage

Sources:

The pg_proctab shipped in pgnodemx provides five SQL wrappers for the legacy process-monitoring interface. It depends on pgnodemx; the package version is 2.0.1, while its SQL installation version is 0.0.10-compat.

Enable

Add pgnodemx to shared_preload_libraries, preserving other entries, then restart PostgreSQL:

shared_preload_libraries = 'pgnodemx'

Install both extensions in the same schema as a superuser:

CREATE EXTENSION pgnodemx;
CREATE EXTENSION pg_proctab VERSION '0.0.10-compat';

The explicit version is required because the main control file has no default version. The audited PGDG RPM packages omit that main control file; use a package containing it before running this command. Querying the underlying OS metrics requires superuser privileges or membership in pg_monitor.

Query

SELECT a.pid, a.query, p.utime, p.stime, p.vsize, p.rss
FROM pg_stat_activity a
JOIN pg_proctab() p ON a.pid = p.pid;

SELECT "user", nice, system, idle, iowait FROM pg_cputime();
SELECT load1, load5, load15, last_pid FROM pg_loadavg();
SELECT memused, memfree, memshared, membuffers, memcached,
       swapused, swapfree, swapcached
FROM pg_memusage();
SELECT devname, reads_completed, writes_completed,
       sectors_read, sectors_written
FROM pg_diskusage();

These functions read Linux process and system statistics visible to the PostgreSQL server. Container namespaces and OS permissions affect what is visible. In this compatibility layer, rss is reported in KiB, memory totals in MiB, and memshared comes from Shmem.

表格阅读