Skip to content
pg_statviz

pg_statviz

pg_statviz : Capture PostgreSQL statistics snapshots for time-series analysis and visualization

Overview

ID Extension Package Version Category License Language
6080
pg_statviz
pg_statviz
1.1
STAT
PostgreSQL
SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d--
No
No
No
Yes
no
no
Relationships
Schemas pgstatviz
Requires
plpgsql
See Also
pgsampler
pgmonitor
pg_mon
timescaledb
town
pg_stl

Cataloged but hidden from default package groups. GitHub release and control are 1.1 while PGXN still serves 1.0. PGDG DEB 1.1 covers active PG14-18 except Ubuntu 22.04 and recommends the separate Python utility, so a normal APT install can pull its Python stack. PGDG RPM remains at 0.9, lacks PG17, and provides PG18 only on EL10; its metadata declares no PostgreSQL dependency, labels GPLv2+ although upstream uses the PostgreSQL License, and describes a CLI although the subpackage contains only extension SQL and control files. The extension itself is pure SQL and PL/pgSQL and needs no preload.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PGDG
1.1
18
17
16
15
14
pg_statviz plpgsql
RPM
PGDG
0.9
18
17
16
15
14
pg_statviz_extension_$v -
DEB
PGDG
1.1
18
17
16
15
14
postgresql-$v-statviz -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
MISS
MISS
PGDG 0.9
PGDG 0.9
PGDG 0.9
el8.aarch64
MISS
MISS
PGDG 0.9
PGDG 0.9
PGDG 0.9
el9.x86_64
MISS
MISS
PGDG 0.9
PGDG 0.9
PGDG 0.9
el9.aarch64
MISS
MISS
PGDG 0.9
PGDG 0.9
PGDG 0.9
el10.x86_64
PGDG 0.9
MISS
PGDG 0.9
PGDG 0.9
PGDG 0.9
el10.aarch64
PGDG 0.9
MISS
PGDG 0.9
PGDG 0.9
PGDG 0.9
d12.x86_64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
d12.aarch64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
d13.x86_64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
d13.aarch64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
u22.x86_64
MISS
MISS
MISS
MISS
MISS
u22.aarch64
MISS
MISS
MISS
MISS
MISS
u24.x86_64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
u24.aarch64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
u26.x86_64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
u26.aarch64
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
PGDG 1.1
Package Version OS ORG SIZE File URL
pg_statviz_extension_18 0.9 el10.x86_64 pgdg 14.7 KiB pg_statviz_extension_18-0.9-1PGDG.rhel10.2.noarch.rpm
pg_statviz_extension_18 0.9 el10.x86_64 pgdg 14.7 KiB pg_statviz_extension_18-0.9-1PGDG.rhel10.1.noarch.rpm
pg_statviz_extension_18 0.9 el10.x86_64 pgdg 15.1 KiB pg_statviz_extension_18-0.9-1PGDG.rhel10.0.noarch.rpm
pg_statviz_extension_18 0.9 el10.aarch64 pgdg 14.7 KiB pg_statviz_extension_18-0.9-1PGDG.rhel10.1.noarch.rpm
pg_statviz_extension_18 0.9 el10.aarch64 pgdg 14.7 KiB pg_statviz_extension_18-0.9-1PGDG.rhel10.0.noarch.rpm
postgresql-18-statviz 1.1 d12.x86_64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg12+1_all.deb
postgresql-18-statviz 1.0 d12.x86_64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg12+1_all.deb
postgresql-18-statviz 1.0 d12.x86_64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg12+1_all.deb
postgresql-18-statviz 1.1 d12.aarch64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg12+1_all.deb
postgresql-18-statviz 1.0 d12.aarch64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg12+1_all.deb
postgresql-18-statviz 1.0 d12.aarch64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg12+1_all.deb
postgresql-18-statviz 1.1 d13.x86_64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg13+1_all.deb
postgresql-18-statviz 1.0 d13.x86_64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg13+1_all.deb
postgresql-18-statviz 1.0 d13.x86_64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg13+1_all.deb
postgresql-18-statviz 1.1 d13.aarch64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg13+1_all.deb
postgresql-18-statviz 1.0 d13.aarch64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg13+1_all.deb
postgresql-18-statviz 1.0 d13.aarch64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg13+1_all.deb
postgresql-18-statviz 1.1 u24.x86_64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg24.04+1_all.deb
postgresql-18-statviz 1.0 u24.x86_64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg24.04+1_all.deb
postgresql-18-statviz 1.0 u24.x86_64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg24.04+1_all.deb
postgresql-18-statviz 1.1 u24.aarch64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg24.04+1_all.deb
postgresql-18-statviz 1.0 u24.aarch64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg24.04+1_all.deb
postgresql-18-statviz 1.0 u24.aarch64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg24.04+1_all.deb
postgresql-18-statviz 1.1 u26.x86_64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg26.04+1_all.deb
postgresql-18-statviz 1.0 u26.x86_64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg26.04+1_all.deb
postgresql-18-statviz 1.0 u26.x86_64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg26.04+1_all.deb
postgresql-18-statviz 1.1 u26.aarch64 pgdg 12.8 KiB postgresql-18-statviz_1.1-1.pgdg26.04+1_all.deb
postgresql-18-statviz 1.0 u26.aarch64 pgdg 12.7 KiB postgresql-18-statviz_1.0-2.pgdg26.04+1_all.deb
postgresql-18-statviz 1.0 u26.aarch64 pgdg 12.6 KiB postgresql-18-statviz_1.0-1.pgdg26.04+1_all.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

pig install pg_statviz;		# install via package name, for the active PG version

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

Create this extension with:

CREATE EXTENSION pg_statviz CASCADE; -- requires plpgsql

Usage

Sources:

pg_statviz v1.1 is a pure SQL and PL/pgSQL statistics snapshot extension plus a separately installed Python visualization utility. The extension stores cumulative and dynamic PostgreSQL statistics in the fixed pgstatviz schema; the utility reads a selected time range and generates charts or optional AI-assisted HTML reports. It requires PostgreSQL 13 or later, needs no shared_preload_libraries, and does not require a restart. The utility requires Python 3.11 or later.

Capture and Retain Snapshots

Have an administrator install the extension, then let a dedicated collection role inherit pg_monitor and schedule pgstatviz.snapshot() with cron or another external job runner.

CREATE EXTENSION pg_statviz;

GRANT pg_monitor TO stats_collector;

SELECT pgstatviz.snapshot();

DELETE FROM pgstatviz.snapshots
WHERE snapshot_tstamp < CURRENT_DATE - 90;

Deleting parent rows cascades to the associated samples. pgstatviz.delete_snapshots() instead truncates the complete history. Pick an interval and retention window based on the shortest event worth observing and the resulting table growth; raw PostgreSQL counters are cumulative and can reset independently, so analyze timestamped deltas rather than treating stored values as rates.

Stored Data and Version Boundaries

The main relations are pgstatviz.snapshots, pgstatviz.buf, pgstatviz.conf, pgstatviz.conn, pgstatviz.db, pgstatviz.io, pgstatviz.lock, pgstatviz.repl, pgstatviz.slru, pgstatviz.wait, and pgstatviz.wal. Samples include configuration values, connection user names and ages, replication application and slot names, waits, locks, I/O, database counters, and WAL counters. Protect the tables, dumps, charts, and reports as operational data.

Configuration is stored only when it changes, so pgstatviz.conf need not contain one row for every snapshot. pg_stat_wal data is collected on PostgreSQL 14 and later; pg_stat_io data is collected on PostgreSQL 16 and later, with PostgreSQL 18’s byte-based fields handled separately. On older supported versions those tables remain part of the schema, but the unavailable collectors are skipped.

The extension marks its snapshot tables for extension-aware dumps. This allows history to be moved with pg_dump, but retention and backup size still need deliberate limits.

Visualize a Time Range

Install the utility separately and pass normal libpq connection options. The analyze command runs every analysis module; individual modules such as conn, io, wait, and wal can be selected when a narrower report is sufficient.

pip install pg_statviz

pg_statviz analyze \
  -h /var/run/postgresql -d mydb -U stats_reader \
  -D 2026-08-01T00:00 2026-08-02T00:00 \
  -O /srv/pg_statviz/reports

Restrict database credentials and report-directory access. A visualization role needs read access to the captured schema but does not need permission to collect or delete snapshots.

Privilege Boundary

The v1.1 installation SQL grants every member of pg_monitor schema usage, function execution, and SELECT, INSERT, DELETE, and TRUNCATE on all pgstatviz tables. Consequently, membership allows both snapshot collection and complete history removal through pgstatviz.delete_snapshots(); it is not a read-only visualization role.

If collection, visualization, and retention administration must be separated, revise the default grants after installation and grant only the required functions and table privileges to dedicated roles. Recheck those grants after an extension update.

Optional AI and Cloud Data Review

Normal chart generation makes no LLM request. AI mode requires the optional pg_statviz[ai] dependencies and an explicit --ai flag. Claude is the default cloud provider and reads ANTHROPIC_API_KEY; Gemini reads GOOGLE_API_KEY; --ai local uses a local Ollama service. The current defaults are claude-sonnet-4-6, gemini-2.5-flash, and gemma4:e4b; these are implementation defaults, not a guarantee that a provider account or local runtime will continue to offer them.

pip install 'pg_statviz[ai]'

pg_statviz analyze \
  -h /var/run/postgresql -d mydb -U stats_reader \
  -D 2026-08-01T00:00 2026-08-02T00:00 \
  -O /srv/pg_statviz/reports \
  --ai gemini

For a cloud provider, the request can include chart images and summarized series together with the captured PostgreSQL version, primary/standby role, hostname, relevant configuration values, deterministic findings, user or role names, and replication identifiers. Treat that as an explicit operational-data export: review provider retention and regional policy, minimize the selected time range, secure generated HTML and PNG files, and use an approved outbound path. The prompt’s data envelopes reduce prompt-injection risk but do not provide confidentiality, authorization, or a substitute for provider governance.

Last updated on