Getting Started
This page is the shortest path: install PG Exporter, connect it to a PostgreSQL instance, verify metrics output, and hook it into Prometheus.
You only need two things: a reachable PostgreSQL 10-19+ (or PgBouncer 1.8+) instance, and permission to create a user in it. For older PostgreSQL 9.1-9.6 instances, see Compatibility.
Install
On Linux amd64 you can download the binary directly. For managed packages, other platforms, containers, Pigsty, and source builds, use the download guide.
Confirm the installation:
Create a Monitoring User
Create a dedicated monitoring user on the target PostgreSQL. The built-in pg_monitor role (PostgreSQL 10+) covers all read permissions the default collectors need:
If you are just trying it out locally as a superuser such as postgres, you can skip this step.
Run and Verify
Use --dry-run to confirm the configuration parses, then start for real:
Without any URL, pg_exporter falls back to the local-first default postgresql:///?sslmode=disable, which fits running on the same host as PostgreSQL. The full URL source precedence (--url > PG_EXPORTER_URL > PGURL > PG_EXPORTER_URL_FILE > default) is documented in the Deployment guide.
Pull the metrics from another terminal:
You should see the three core built-in metrics:
pg_up 1 means the pipeline works — the remaining 600+ metrics (pg_db_*, pg_table_*, pg_wal_*, …) all come from the declarative collector definitions in pg_exporter.yml. If pg_up is 0, restart with pg_exporter --log.level=debug and inspect the connection error.
Hook into Prometheus
Add a scrape target in prometheus.yml:
Collectors cache results per their ttl (most realtime collectors use ttl: 10): as long as the TTL is below the scrape interval, every scrape gets fresh data, while high-frequency scraping can never overwhelm the database. This is also why setting scrape_interval below the common TTLs is not recommended.
That’s it. For Grafana, you can reuse the PostgreSQL dashboards from Pigsty, or explore the live demo.
Troubleshooting
| Symptom | What to do |
|---|---|
pg_up 0, connection fails |
Run pg_exporter --log.level=debug and read the error; check URL, pg_hba.conf, and network reachability |
| Some metrics are missing | curl localhost:9630/explain to see each collector’s planning verdict (version gates, tags, predicates) |
| A collector keeps failing | curl localhost:9630/stat for per-collector error counters and durations |
| Scrapes are slow | Find the slow collector in /stat, raise its ttl, or set skip: true |
/stat, /explain, and /reload are management endpoints — protect them with --web.config.file (TLS/auth) or keep them on a trusted network in production. See the API Reference.
Next Steps
- Monitor PgBouncer, enable auto-discovery, deploy with systemd / Docker / Kubernetes: Deployment guide
- Understand and customize collectors (GAUGE/COUNTER/HISTOGRAM, TTL, tags, version gates): Configuration reference
- Health check and primary/replica traffic routing endpoints (
/up,/primary,/replica): API Reference