API Reference
pg_exporter provides four types of HTTP endpoints: metrics, health checks, traffic routing, and operational management.
The default listen port is :9630. The following table lists all endpoints:
| Endpoint | Method | Description |
|---|---|---|
/metrics | GET | Prometheus metrics endpoint (path configurable via --web.telemetry-path) |
/up | GET | Aliveness check; aliases /health, /liveness, /readiness, /read |
/primary | GET | Primary check; aliases /leader, /master, /read-write, /rw |
/replica | GET | Replica check; aliases /standby, /slave, /read-only, /ro |
/reload | GET/POST | Hot-reload collector configuration |
/explain | GET | Show per-collector planning decisions |
/stat | GET | Per-collector runtime statistics (hits / errors / duration) |
/version | GET | Version and build information (plain text) |
/ | GET | Landing page linking to the metrics endpoint |
Health and routing endpoints return the cached state from background probes: primary, replica, down, starting, or unknown.
They do not query the database for each HTTP request. Thus, frequent probes cannot overload the database.
Metrics Endpoint
GET /metrics
This endpoint returns all collected metrics in Prometheus format.
Request
Response
Response Format
Metrics follow the Prometheus exposition format:
Self-Monitoring Metrics
In addition to metrics from YAML collectors, /metrics returns the exporter’s runtime metrics.
Use --disable-intro to disable the pg_exporter_* metrics.
The prefix follows --namespace. In pgBouncer mode, the prefix is pgbouncer_.
| Metric | Labels | Description |
|---|---|---|
pg_up | — | 1 when the target database is reachable, 0 otherwise |
pg_version | — | Server version in server_version_num format |
pg_in_recovery | — | 1 when in recovery mode (replica) |
pg_exporter_build_info | version, revision, … | Constant 1 with build info in labels |
pg_exporter_up | — | Constant 1 while the exporter is alive |
pg_exporter_uptime | — | Seconds since the exporter started |
pg_exporter_scrape_total_count / _error_count | — | Cumulative scrape / failure counts |
pg_exporter_scrape_duration | — | Duration of the last scrape in seconds |
pg_exporter_last_scrape_time | — | Timestamp of the last scrape |
pg_exporter_server_scrape_* | datname | Per-database scrape duration and success/failure counters |
pg_exporter_query_scrape_duration | datname, query | Last execution duration per collector |
pg_exporter_query_scrape_total_count / _error_count | datname, query | Execution / failure counts per collector |
pg_exporter_query_scrape_hit_count / _metric_count | datname, query | Rows returned / metrics emitted per collector |
pg_exporter_query_scrape_predicate_skip_count | datname, query | Times skipped because a predicate returned false |
pg_exporter_query_cache_ttl | datname, query | Result cache TTL per collector |
Use pg_exporter_query_scrape_duration and _error_count to identify slow or failed collectors.
These metrics provide a machine-readable equivalent of /stat.
Health Checks
Health endpoints provide multiple ways to monitor PG Exporter and the target database state.
GET /up
This endpoint checks availability from the cached background probe state. It does not probe the database for each HTTP request.
Response Codes
| Code | Status | Description |
|---|---|---|
| 200 | OK | Target is available (primary / replica) |
| 503 | Service Unavailable | Target is unavailable (down / starting / unknown) |
Example
GET /health
Alias of /up with identical behavior.
GET /liveness and GET /readiness
These aliases use the same handler and behavior as /up. Use them for Kubernetes probes:
Both endpoints return 503 when the target database is unreachable. To prevent a database failure from restarting the exporter Pod, use a TCP liveness probe on the listen port.
Traffic Routing
Load balancers and proxies use these endpoints to route traffic by server role.
GET /primary
Check whether the server is a primary instance.
Response Codes
| Code | Status | Description |
|---|---|---|
| 200 | OK | Server is primary and accepting writes |
| 404 | Not Found | Server is not primary and is acting as a replica |
| 503 | Service Unavailable | Server is unavailable (down / starting / unknown) |
Aliases
/leader/master/read-write/rw
Example
GET /replica
Check whether the server is a replica instance.
Response Codes
| Code | Status | Description |
|---|---|---|
| 200 | OK | Server is a replica and in recovery |
| 404 | Not Found | Server is not a replica and is acting as primary |
| 503 | Service Unavailable | Server is unavailable (down / starting / unknown) |
Aliases
/standby/read-only/ro
/slave remains compatible, but /replica is the preferred name.
Example
GET /read
Check whether the server can handle read traffic. Both primaries and replicas may return success.
Response Codes
| Code | Status | Description |
|---|---|---|
| 200 | OK | Server is healthy and can handle reads |
| 503 | Service Unavailable | Server is unavailable (down / starting / unknown) |
Example
Operational Endpoints
GET /reload / POST /reload
Reload configuration without restarting the exporter.
Request
Response
Response Codes
| Code | Status | Description |
|---|---|---|
| 200 | OK | Reload completed successfully |
| 500 | Internal Server Error | Reload failed and returns fail to reload: ... |
| 405 | Method Not Allowed | Non-GET/POST request, with Allow: GET, POST |
Use Cases
- Update collector definitions
- Change query parameters
- Modify cache TTL values
- Add or remove collectors
Reload updates collector configuration and query plans. To change process settings, such as listen addresses or CLI arguments, restart the exporter.
/reload, /explain, and /stat are management endpoints.
If the exporter is reachable outside localhost or a trusted private network, protect these endpoints.
Use --web.config.file, or restrict access through a reverse proxy or firewall.
GET /explain
Display planned collector execution details for all configured collectors.
Request
Response
GET /stat
Show runtime statistics, including collector execution times and success/error counters.
Request
Response
Use this endpoint to identify slow or failed collectors.
Using with Load Balancers
HAProxy Example
A Note on Nginx
Open-source Nginx does not support active HTTP health checks outside the traffic connection.
The health_check directive requires NGINX Plus.
PostgreSQL traffic also requires the stream module instead of http proxying.
To route PostgreSQL traffic by role, use HAProxy as shown above, or a solution such as Patroni + vip-manager.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)