PostgreSQL ships with powerful built-in statistics views, but navigating raw pg_stat_* tables in production is cumbersome. Specialized admin tools bridge this gap by providing real-time query analysis, connection monitoring, and performance diagnostics. This guide compares three distinct approaches: pgCenter (terminal-based admin dashboard), pg_stat_monitor (enhanced query statistics extension from Percona), and pg_stat_statements (PostgreSQL’s built-in query performance tracker). Each serves a different role in the PostgreSQL observability stack.
What Each Tool Does
| Feature | pgCenter | pg_stat_monitor | pg_stat_statements |
|---|---|---|---|
| Type | CLI admin dashboard | PostgreSQL extension | PostgreSQL extension (built-in) |
| Interface | Terminal (ncurses) | SQL views | SQL views |
| Real-time Monitoring | Yes (live refresh) | No (accumulated stats) | No (accumulated stats) |
| Query Profiling | Yes (live) | Yes (with histograms) | Yes (basic) |
| Connection Tracking | Yes (per-connection detail) | Partial | No |
| Lock Analysis | Yes (blocking queries) | No | No |
| Replication Monitoring | Yes (lag, WAL stats) | No | No |
| Table/Index Stats | Yes (live) | No | No |
| Query Histograms | No | Yes (bucketed response times) | No |
| Client IP Tracking | Yes | Yes | No |
| Query Plans | No | No | No |
| Installation | Standalone binary | CREATE EXTENSION | CREATE EXTENSION (contrib) |
| Overhead | None (reads system catalogs) | Low (query parsing) | Low (query hashing) |
| PostgreSQL Versions | 12+ | 13+ | 9.2+ |
| GitHub Stars | 1,600+ | 570+ | Built into PostgreSQL |
pgCenter: Terminal Admin Dashboard
pgCenter is a real-time administrative tool that provides an ncurses-based dashboard for monitoring PostgreSQL server health. Unlike extensions that modify query execution, pgCenter reads existing system catalogs and statistics views — meaning zero overhead on your production workload.
What You Can Monitor
- Activity — Live query list with duration, state, and blocking information
- Tables — I/O statistics, row operations, and index usage per table
- Indexes — Scan counts, tuple reads, and bloat estimation
- Replication — Streaming replication lag, WAL generation rate, and standby status
- Configuration — Runtime parameter values with diff detection on reload
- Filespaces — Table size, index size, and toast table usage
Docker Compose Setup
| |
Using pgCenter in Production
| |
pg_stat_monitor: Enhanced Query Statistics
pg_stat_monitor is a Percona-developed PostgreSQL extension that extends the capabilities of pg_stat_statements with additional metrics. It captures query execution statistics grouped into time buckets, enabling trend analysis and performance regression detection.
Key Enhancements Over pg_stat_statements
- Time-bucketed statistics — Stats are grouped into configurable time windows (default: 1 minute), enabling trend analysis
- Query histograms — Response time distribution across configurable buckets
- Client information — Application name, database user, and client IP address per query
- Query relationships — Parent-child query tracking for stored procedures
- Plans and relations — Tables and indexes accessed by each query pattern
- Top query tracking — Identifies the most resource-intensive queries per time bucket
Installation and Configuration
| |
Querying Performance Data
| |
Docker Compose with pg_stat_monitor
| |
pg_stat_statements: Built-In Query Tracking
pg_stat_statements is the most widely used PostgreSQL performance extension, included in the contrib package. It tracks execution statistics for all SQL statements executed by the server, providing a foundation for query performance analysis.
What It Tracks
- Call count and total/mean/min/max execution time
- Rows returned and shared/local/temp block I/O statistics
- Temporary file usage and WAL generation per query pattern
- Query plan identification via normalized query fingerprinting
Configuration
| |
Essential Queries
| |
Performance Overhead Comparison
| Metric | pgCenter | pg_stat_monitor | pg_stat_statements |
|---|---|---|---|
| CPU overhead | None (read-only) | ~1-3% | ~1-2% |
| Memory overhead | None | 50-200 MB (shared memory) | 20-100 MB (shared memory) |
| I/O overhead | None | None | None |
| Query latency impact | None | < 1ms per query | < 0.5ms per query |
Why Self-Host PostgreSQL Admin Tools?
Running your own PostgreSQL admin tools on dedicated infrastructure eliminates the per-database licensing fees charged by enterprise APM vendors. Tools like pgCenter provide the same real-time diagnostics that Datadog or New Relic offer for database monitoring, but without per-host pricing or data egress charges. For teams managing dozens of PostgreSQL instances, self-hosted admin tools pay for themselves within months.
Self-hosted PostgreSQL tooling also integrates seamlessly with existing infrastructure monitoring. Combine pgCenter with Prometheus node exporters, Grafana dashboards, and centralized log aggregation for comprehensive database observability. The zero-overhead design of pgCenter means it can run continuously on production servers without affecting query latency.
Running PostgreSQL admin tools on your own infrastructure means query performance data never leaves your network. This is essential for compliance with data protection regulations that restrict where performance telemetry can be stored. Self-hosted tools also avoid the per-database or per-query pricing models of cloud-based monitoring services.
For teams managing multiple PostgreSQL instances, combining pgCenter for real-time diagnostics with pg_stat_monitor for historical trend analysis provides comprehensive coverage without the cost of enterprise APM platforms. For related reading, see our PostgreSQL performance dashboards guide and database query profiling tools. If you need connection pooling alongside monitoring, our connection pooler comparison covers PgBouncer, ProxySQL, and Odyssey.
FAQ
Should I use pg_stat_statements or pg_stat_monitor?
Start with pg_stat_statements — it is built into PostgreSQL, has zero external dependencies, and covers the most common query analysis needs. Upgrade to pg_stat_monitor if you need time-bucketed statistics for trend analysis, query response time histograms, or client IP tracking. pg_stat_monitor is a superset of pg_stat_statements functionality.
Does pgCenter require installing a PostgreSQL extension?
No. pgCenter reads from PostgreSQL’s built-in statistics views (pg_stat_activity, pg_stat_user_tables, etc.) and system catalogs. It requires no extensions, no shared preload libraries, and no server restart. The only requirement is a database user with sufficient privileges to read these views.
Can I use pg_stat_monitor alongside pg_stat_statements?
Yes, but not simultaneously in the same shared_preload_libraries configuration. pg_stat_monitor provides all the functionality of pg_stat_statements plus additional metrics, so you should use one or the other. Using both would create redundant tracking and unnecessary overhead.
How do I identify blocking queries with pgCenter?
In pgCenter’s activity view (accessed via pgcenter top), blocked queries are highlighted with their blocking PID displayed. The tool shows lock type, wait duration, and the blocking query text. This makes it easy to identify long-running transactions that are preventing other queries from proceeding.
What is the recommended shared memory allocation for pg_stat_monitor?
Percona recommends starting with pg_stat_monitor.pgsm_query_shared_buffers = 100 (100 MB) for small databases and increasing to 500 MB or more for high-traffic production systems. Monitor the pg_stat_monitor view for query truncation warnings, which indicate the buffer is too small.
How often should I reset pg_stat_statements statistics?
Reset statistics after major deployments or configuration changes to establish a fresh baseline. In continuous monitoring setups, most teams reset weekly or monthly. Use SELECT pg_stat_statements_reset() to clear accumulated data. Note that resetting loses historical data, so export important metrics before resetting.