Getting Started
Follow these steps to install pg_exporter, connect to PostgreSQL, check metrics, and configure Prometheus.
You need a reachable PostgreSQL 10-19+ or pgBouncer 1.8+ instance and permission to create a user in it. For PostgreSQL 9.1-9.6, see Compatibility.
Step 1: Install
On Linux amd64, download the binary directly. For other platforms and RPM/DEB/Docker options, see the Installation guide.
Confirm the installation:
Step 2: Create a Monitoring User
Create a dedicated monitoring user on the target PostgreSQL instance.
Start with the built-in pg_monitor role in PostgreSQL 10+:
On PostgreSQL 10–13, an administrator must also run the following grant in the exporter’s main connection database to read subscription OIDs. Granting it only in the database owning the subscription is insufficient. This does not expose the password-bearing subconninfo column. PostgreSQL 14+ needs no extra grant under standard catalog ACLs.
For a local test with a superuser such as postgres, you can skip this step.
Step 3: Run and Verify
Use --dry-run to check that the configuration parses correctly. Then start the exporter:
If you do not specify a URL, pg_exporter uses postgresql:///?sslmode=disable to connect on the same host.
The URL source order is --url > PG_EXPORTER_URL > PGURL > PG_EXPORTER_URL_FILE > default.
See the Deployment guide for details.
Get the metrics from another terminal:
You should see the three core built-in metrics:
pg_up 1 shows that the connection and metric collection work.
The pg_exporter.yml bundle defines 460 distinct metric names (pg_db_*, pg_table_*, pg_wal_*, and others), with applicable metrics selected by version, role, and database objects.
If pg_up is 0, restart with pg_exporter --log.level=debug and examine the connection error.
Step 4: Hook into Prometheus
Add a scrape target in prometheus.yml:
Collectors cache results for their ttl. Most realtime collectors use ttl: 10.
If the TTL is less than the scrape interval, each scrape gets fresh data.
The cache also prevents high-frequency scrapes from overloading the database.
Do not set scrape_interval below the common collector TTLs.
For Grafana, use the PostgreSQL dashboards from Pigsty, or view 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.
In production, protect them with --web.config.file for TLS/auth, or keep them on a trusted network.
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
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)