Skip to content
pg_stat_monitor

pg_stat_monitor

pg_stat_monitor : The pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL contrib module pg_stat_statements. pg_stat_monitor provides aggregated statistics, client information, plan details including plan, and histogram information.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
6230
pg_stat_monitor
pg_stat_monitor
2.3.2
STAT
BSD 3-Clause
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd-r
No
Yes
Yes
Yes
yes
no
Relationships
See Also
pg_show_plans
pg_stat_kcache
pg_stat_statements
pg_qualstats
pg_store_plans
pgsentinel
auto_explain
logerrors

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
2.3.2
18
17
16
15
14
pg_stat_monitor-
RPM
PIGSTY
2.3.2
18
17
16
15
14
pg_stat_monitor_$v-
DEB
PIGSTY
2.3.2
18
17
16
15
14
postgresql-$v-pg-stat-monitor-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
el8.aarch64
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
el9.x86_64
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
el9.aarch64
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
el10.x86_64
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
el10.aarch64
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
PGDG 2.3.2
d12.x86_64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
d12.aarch64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
d13.x86_64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
d13.aarch64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
u22.x86_64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
u22.aarch64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
u24.x86_64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
u24.aarch64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
u26.x86_64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
u26.aarch64
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PIGSTY 2.3.2
PackageVersionOSORGSIZEFile URL
pg_stat_monitor_182.3.2el8.x86_64pgdg43.7 KiBpg_stat_monitor_18-2.3.2-1PGDG.rhel8.10.x86_64.rpm
pg_stat_monitor_182.3.1el8.x86_64pigsty43.3 KiBpg_stat_monitor_18-2.3.1-1PIGSTY.el8.x86_64.rpm
pg_stat_monitor_182.3.1el8.x86_64pgdg43.6 KiBpg_stat_monitor_18-2.3.1-1PGDG.rhel8.10.x86_64.rpm
pg_stat_monitor_182.3.2el8.aarch64pgdg42.3 KiBpg_stat_monitor_18-2.3.2-1PGDG.rhel8.10.aarch64.rpm
pg_stat_monitor_182.3.1el8.aarch64pigsty42.1 KiBpg_stat_monitor_18-2.3.1-1PIGSTY.el8.aarch64.rpm
pg_stat_monitor_182.3.1el8.aarch64pgdg42.2 KiBpg_stat_monitor_18-2.3.1-1PGDG.rhel8.10.aarch64.rpm
pg_stat_monitor_182.3.2el9.x86_64pgdg42.5 KiBpg_stat_monitor_18-2.3.2-1PGDG.rhel9.7.x86_64.rpm
pg_stat_monitor_182.3.1el9.x86_64pigsty42.0 KiBpg_stat_monitor_18-2.3.1-1PIGSTY.el9.x86_64.rpm
pg_stat_monitor_182.3.1el9.x86_64pgdg42.4 KiBpg_stat_monitor_18-2.3.1-1PGDG.rhel9.7.x86_64.rpm
pg_stat_monitor_182.3.2el9.aarch64pgdg41.9 KiBpg_stat_monitor_18-2.3.2-1PGDG.rhel9.7.aarch64.rpm
pg_stat_monitor_182.3.1el9.aarch64pigsty41.8 KiBpg_stat_monitor_18-2.3.1-1PIGSTY.el9.aarch64.rpm
pg_stat_monitor_182.3.1el9.aarch64pgdg41.7 KiBpg_stat_monitor_18-2.3.1-1PGDG.rhel9.7.aarch64.rpm
pg_stat_monitor_182.3.2el10.x86_64pgdg42.7 KiBpg_stat_monitor_18-2.3.2-1PGDG.rhel10.1.x86_64.rpm
pg_stat_monitor_182.3.1el10.x86_64pigsty42.2 KiBpg_stat_monitor_18-2.3.1-1PIGSTY.el10.x86_64.rpm
pg_stat_monitor_182.3.1el10.x86_64pgdg42.6 KiBpg_stat_monitor_18-2.3.1-1PGDGrhel10.1.x86_64.rpm
pg_stat_monitor_182.3.2el10.aarch64pgdg42.4 KiBpg_stat_monitor_18-2.3.2-1PGDG.rhel10.1.aarch64.rpm
pg_stat_monitor_182.3.1el10.aarch64pigsty42.1 KiBpg_stat_monitor_18-2.3.1-1PIGSTY.el10.aarch64.rpm
pg_stat_monitor_182.3.1el10.aarch64pgdg42.1 KiBpg_stat_monitor_18-2.3.1-1PGDGrhel10.1.aarch64.rpm
postgresql-18-pg-stat-monitor2.3.2d12.x86_64pigsty74.6 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-stat-monitor2.3.2d12.aarch64pigsty72.8 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-stat-monitor2.3.2d13.x86_64pigsty74.5 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-stat-monitor2.3.2d13.aarch64pigsty73.3 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-stat-monitor2.3.2u22.x86_64pigsty80.9 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-stat-monitor2.3.2u22.aarch64pigsty79.7 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-stat-monitor2.3.2u24.x86_64pigsty77.8 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~noble_amd64.deb
postgresql-18-pg-stat-monitor2.3.2u24.aarch64pigsty76.9 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~noble_arm64.deb
postgresql-18-pg-stat-monitor2.3.2u26.x86_64pigsty76.8 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-stat-monitor2.3.2u26.aarch64pigsty75.6 KiBpostgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_stat_monitor;		# 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 pg_stat_monitor;		# install via package name, for the active PG version

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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_stat_monitor';

Create this extension with:

CREATE EXTENSION pg_stat_monitor;

Usage

pg_stat_monitor: query performance monitoring tool for PostgreSQL

pg_stat_monitor is an advanced replacement for pg_stat_statements that aggregates statistics into configurable time-based buckets, provides query origin information, actual parameter capture, and query plan details.

Querying Statistics

-- Basic query monitoring
SELECT application_name, userid::regrole AS user_name,
       datname AS database_name, substr(query, 0, 50) AS query,
       calls, client_ip
FROM pg_stat_monitor;

-- Bucket-based time analysis
SELECT bucket, bucket_start_time, query, calls,
       mean_exec_time, total_exec_time
FROM pg_stat_monitor
ORDER BY total_exec_time DESC;

-- Show query plans
SELECT query, query_plan FROM pg_stat_monitor
WHERE query_plan IS NOT NULL;

Key Features

  • Time-based buckets: Statistics are grouped into configurable intervals for more accurate analysis
  • Client IP tracking: Each query records the originating client IP address
  • Actual parameters: Optionally capture real query parameter values instead of placeholders
  • Query plans: Each query is accompanied by its actual execution plan
  • Top query tracking: Identify the most resource-intensive queries per bucket
  • Histogram support: Visual timing distribution via histogram function

Functions

-- Reset all statistics
SELECT pg_stat_monitor_reset();

-- View internal info
SELECT * FROM pg_stat_monitor_info;

Configuration

Key parameters (set in postgresql.conf):

ParameterDescription
pg_stat_monitor.pgsm_maxMaximum number of statements tracked
pg_stat_monitor.pgsm_query_max_lenMaximum query length
pg_stat_monitor.pgsm_bucket_timeBucket duration in seconds
pg_stat_monitor.pgsm_max_bucketsMaximum number of buckets
pg_stat_monitor.pgsm_enable_query_planEnable query plan capture
pg_stat_monitor.pgsm_trackTrack: top, all, or none
Last updated on