Production deployment
Run with systemd, Docker, or Kubernetes.
Quick start
Install PG Exporter, create a monitoring user, and connect it to PostgreSQL. Then add its metrics endpoint to Prometheus.
You need Linux amd64, PostgreSQL 10 or later on the same host, sudo access, and database administrator access.
Step 01
Download and install the binary and its collector configuration.
The checksum result is OK. The installed version is v1.6.0.
Other platforms and package installation commands are on the download page.
Step 02
Connect to PostgreSQL as its administrator:
Replace change-me with a password. Then create the monitoring role:
On PostgreSQL 10–13, also run this in the main connection database (postgres in this guide):
PostgreSQL 14+ needs no extra grant under the standard catalog ACLs. This grant does not expose subscription passwords.
Type \q to return to the shell. Use the same password in the connection URL below.
Step 03
Start the exporter in the foreground. It listens on this host only.
In the URL, percent-encode reserved characters in the password (for example, # becomes %23).
Run this command in another terminal:
For remote databases, TLS, or password files, see production deployment.
Example output
pg_up 1 reports a main database scrape without a fatal error. This example shows a PostgreSQL 17 primary.
pg_up 1
pg_version 170000
pg_in_recovery 0Step 04
Add this target to prometheus.yml. This example uses Prometheus on the same host.
Reload Prometheus. Open its Targets page and check that the target is UP. If Prometheus runs elsewhere, configure a reachable listener and target address as shown in production deployment.
Use Pigsty dashboards to view the metrics, or explore the live demo.
Troubleshooting
Use the logs for connection errors, /explain for selected queries, and /stat for query statistics.
Read the exporter log. Check the host, port, database, credentials, and pg_hba.conf. A fatal collector error can also set pg_up to 0.
Read /explain to see the collectors selected for the main database. Compare their version limits, tags, and SQL with your target. Read /stat for error counts and metric counts. Check the exporter logs for error details.