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
|
Source
pig build pkg pg_stat_monitor; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Config 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