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

ID Extension Package Version Category License Language
6230
pg_stat_monitor
pg_stat_monitor
2.3.2
STAT
BSD 3-Clause
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--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

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
Package Version OS ORG SIZE File URL
pg_stat_monitor_18 2.3.2 el8.x86_64 pgdg 43.7 KiB pg_stat_monitor_18-2.3.2-1PGDG.rhel8.10.x86_64.rpm
pg_stat_monitor_18 2.3.1 el8.x86_64 pigsty 43.3 KiB pg_stat_monitor_18-2.3.1-1PIGSTY.el8.x86_64.rpm
pg_stat_monitor_18 2.3.1 el8.x86_64 pgdg 43.6 KiB pg_stat_monitor_18-2.3.1-1PGDG.rhel8.10.x86_64.rpm
pg_stat_monitor_18 2.3.2 el8.aarch64 pgdg 42.3 KiB pg_stat_monitor_18-2.3.2-1PGDG.rhel8.10.aarch64.rpm
pg_stat_monitor_18 2.3.1 el8.aarch64 pigsty 42.1 KiB pg_stat_monitor_18-2.3.1-1PIGSTY.el8.aarch64.rpm
pg_stat_monitor_18 2.3.1 el8.aarch64 pgdg 42.2 KiB pg_stat_monitor_18-2.3.1-1PGDG.rhel8.10.aarch64.rpm
pg_stat_monitor_18 2.3.2 el9.x86_64 pgdg 42.5 KiB pg_stat_monitor_18-2.3.2-1PGDG.rhel9.7.x86_64.rpm
pg_stat_monitor_18 2.3.1 el9.x86_64 pigsty 42.0 KiB pg_stat_monitor_18-2.3.1-1PIGSTY.el9.x86_64.rpm
pg_stat_monitor_18 2.3.1 el9.x86_64 pgdg 42.4 KiB pg_stat_monitor_18-2.3.1-1PGDG.rhel9.7.x86_64.rpm
pg_stat_monitor_18 2.3.2 el9.aarch64 pgdg 41.9 KiB pg_stat_monitor_18-2.3.2-1PGDG.rhel9.7.aarch64.rpm
pg_stat_monitor_18 2.3.1 el9.aarch64 pigsty 41.8 KiB pg_stat_monitor_18-2.3.1-1PIGSTY.el9.aarch64.rpm
pg_stat_monitor_18 2.3.1 el9.aarch64 pgdg 41.7 KiB pg_stat_monitor_18-2.3.1-1PGDG.rhel9.7.aarch64.rpm
pg_stat_monitor_18 2.3.2 el10.x86_64 pgdg 42.7 KiB pg_stat_monitor_18-2.3.2-1PGDG.rhel10.1.x86_64.rpm
pg_stat_monitor_18 2.3.1 el10.x86_64 pigsty 42.2 KiB pg_stat_monitor_18-2.3.1-1PIGSTY.el10.x86_64.rpm
pg_stat_monitor_18 2.3.1 el10.x86_64 pgdg 42.6 KiB pg_stat_monitor_18-2.3.1-1PGDGrhel10.1.x86_64.rpm
pg_stat_monitor_18 2.3.2 el10.aarch64 pgdg 42.4 KiB pg_stat_monitor_18-2.3.2-1PGDG.rhel10.1.aarch64.rpm
pg_stat_monitor_18 2.3.1 el10.aarch64 pigsty 42.1 KiB pg_stat_monitor_18-2.3.1-1PIGSTY.el10.aarch64.rpm
pg_stat_monitor_18 2.3.1 el10.aarch64 pgdg 42.1 KiB pg_stat_monitor_18-2.3.1-1PGDGrhel10.1.aarch64.rpm
postgresql-18-pg-stat-monitor 2.3.2 d12.x86_64 pigsty 74.6 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-stat-monitor 2.3.2 d12.aarch64 pigsty 72.8 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-stat-monitor 2.3.2 d13.x86_64 pigsty 74.5 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-stat-monitor 2.3.2 d13.aarch64 pigsty 73.3 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-stat-monitor 2.3.2 u22.x86_64 pigsty 80.9 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-stat-monitor 2.3.2 u22.aarch64 pigsty 79.7 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-stat-monitor 2.3.2 u24.x86_64 pigsty 77.8 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~noble_amd64.deb
postgresql-18-pg-stat-monitor 2.3.2 u24.aarch64 pigsty 76.9 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~noble_arm64.deb
postgresql-18-pg-stat-monitor 2.3.2 u26.x86_64 pigsty 76.8 KiB postgresql-18-pg-stat-monitor_2.3.2-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-stat-monitor 2.3.2 u26.aarch64 pigsty 75.6 KiB postgresql-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):

Parameter Description
pg_stat_monitor.pgsm_max Maximum number of statements tracked
pg_stat_monitor.pgsm_query_max_len Maximum query length
pg_stat_monitor.pgsm_bucket_time Bucket duration in seconds
pg_stat_monitor.pgsm_max_buckets Maximum number of buckets
pg_stat_monitor.pgsm_enable_query_plan Enable query plan capture
pg_stat_monitor.pgsm_track Track: top, all, or none
Last updated on