PG EXPORTER
Advanced PostgreSQL & pgBouncer metrics exporter for Prometheus
PG Exporter brings ultimate monitoring experience to your PostgreSQL with declarative config, dynamic planning, and customizable collectors.
The bundled configuration defines 460 distinct metrics across 96 collector branches and 59 namespaces.
Actual time-series counts depend on the PostgreSQL version, enabled collectors, databases, objects, and labels.
Check https://demo.pigsty.io for live demo, which is built upon this exporter by Pigsty.

Features
- Highly Customizable: Define almost all metrics through declarative YAML configs
- Version Coverage: PostgreSQL 10–18 and 19 RC1 verified with the regular configuration; PostgreSQL 9.1–9.6 with the legacy configuration; PgBouncer verified through 1.26.1
- Fine-grained Control: Configure timeout, caching, skip conditions, and fatality per collector
- Dynamic Planning: Define multiple query branches based on different conditions
- Self-monitoring: Rich metrics about pg_exporter itself for complete observability
- Production-Ready: Battle-tested in real-world environments across 12K+ cores for 6+ years
- Auto-discovery: Automatically discover and monitor multiple databases within an instance
- Health Check APIs: Comprehensive HTTP endpoints for service health and traffic routing
- Extension Support:
timescaledb, citus, pg_stat_statements, pg_wait_sampling,...
- Local-first URL behavior: Built for on-host deployment, with implicit local target fallback and automatic
sslmode=disable when omitted
Legacy support for PostgreSQL 9.1–9.6 is maintained separately in legacy/ (historical support, not bundled in release packages).
v1.6.1
Built with Go 1.27.4, this maintenance release hardens collector isolation, connection URL normalization, and SQL edge cases without changing public metric names, label keys, or HTTP contracts:
- Preserve URI authority on hostless PostgreSQL URLs (for example
postgresql://?host=/var/run/postgresql), redact sslpassword in logs, and strip conflicting service parameters during database discovery.
- Reject duplicate scalar label sets within a collector before gathering; non-fatal failures let other collectors continue, while histogram-only queries still aggregate repeated labels. Validate
--namespace at startup and keep invalid internal labels or user build-info overrides from causing panics or misleading metadata.
- Make removed/replaced child-pool cleanup safe, reject non-finite
scale / default, and repair predicate TTL rendering on the HTML explain page.
- Fix
pg_table partitioned-table age (relfrozenxid = 0 no longer reports 2147483647) and NULL scan sums on unindexed tables, pg_tsdb_hypertable identifier quoting, pg_table_size temp/TOAST schema filtering, pg_activity negative clock-skew durations, and collector HELP descriptions.
- Inject build metadata in
Dockerfile, add ExecReload to pg_exporter.service, and expand version-coverage tests across PostgreSQL 10–19 and PgBouncer 1.8–1.26.
- See the v1.6.1 release notes for fixes and upgrade steps. Authoritative manuals and design records live at exp.pgsty.com.
Quick Start
RPM / DEB / Tarball available in the GitHub release page, and Pigsty's YUM / APT Infra Repo.
To run this exporter, you need to pass the postgres/pgbouncer URL via env or arg:
PG_EXPORTER_URL='postgres://user:pass@host:port/postgres' pg_exporter
curl http://localhost:9630/metrics # access metrics
There are built-in metrics such as pg_up, pg_version, pg_in_recovery, pg_exporter_build_info, and exporter self-metrics under pg_exporter_* (disable with --disable-intro).
All other metrics are defined in the pg_exporter.yml config file.
There are two monitoring dashboards in the monitor/ directory.
You can use Pigsty to monitor existing PostgreSQL cluster or RDS, it will setup pg_exporter for you.
Usage
usage: pg_exporter [<flags>]
Flags:
-h, --[no-]help Show context-sensitive help (also try --help-long and --help-man).
-u, --url=URL postgres target url
-c, --config=CONFIG path to config dir or file
--web.listen-address=:9630 ...
Addresses on which to expose metrics and web interface.
--web.config.file="" Path to configuration file that can enable TLS or authentication.
-l, --label="" constant labels: comma separated list of label=value pair ($PG_EXPORTER_LABEL)
-t, --tag="" tags,comma separated list of server tag ($PG_EXPORTER_TAG)
-C, --[no-]disable-cache force not using cache ($PG_EXPORTER_DISABLE_CACHE)
-m, --[no-]disable-intro disable internal/exporter self metrics ($PG_EXPORTER_DISABLE_INTRO)
-a, --[no-]auto-discovery automatically scrape all database for given server ($PG_EXPORTER_AUTO_DISCOVERY)
-x, --exclude-database="template0,template1,postgres"
excluded databases when enabling auto-discovery ($PG_EXPORTER_EXCLUDE_DATABASE)
-i, --include-database="" included databases when enabling auto-discovery ($PG_EXPORTER_INCLUDE_DATABASE)
-n, --namespace="" prefix of built-in metrics, (pg|pgbouncer) by default ($PG_EXPORTER_NAMESPACE)
-f, --[no-]fail-fast fail fast instead of waiting during start-up ($PG_EXPORTER_FAIL_FAST)
-T, --connect-timeout=100 connect timeout in ms, 100 by default ($PG_EXPORTER_CONNECT_TIMEOUT)
-P, --web.telemetry-path="/metrics"
URL path under which to expose metrics. ($PG_EXPORTER_TELEMETRY_PATH)
-D, --[no-]dry-run dry run and print raw configs
-E, --[no-]explain explain server planned queries
--log.level="info" log level: debug|info|warn|error
--log.format="logfmt" log format: logfmt|json
--[no-]version Show application version.
Parameters could be given via command-line args or environment variables.
| CLI Arg |
Environment Variable |
Default Value |
--url |
PG_EXPORTER_URL / PGURL / PG_EXPORTER_URL_FILE |
postgresql:///?sslmode=disable |
--config |
PG_EXPORTER_CONFIG |
pg_exporter.yml |
--label |
PG_EXPORTER_LABEL |
|
--tag |
PG_EXPORTER_TAG |
|
--auto-discovery |
PG_EXPORTER_AUTO_DISCOVERY |
true |
--disable-cache |
PG_EXPORTER_DISABLE_CACHE |
false |
--disable-intro |
PG_EXPORTER_DISABLE_INTRO |
false |
--fail-fast |
PG_EXPORTER_FAIL_FAST |
false |
--exclude-database |
PG_EXPORTER_EXCLUDE_DATABASE |
template0,template1,postgres |
--include-database |
PG_EXPORTER_INCLUDE_DATABASE |
|
--namespace |
PG_EXPORTER_NAMESPACE |
pg|pgbouncer |
--connect-timeout |
PG_EXPORTER_CONNECT_TIMEOUT |
100 |
--dry-run |
|
false |
--explain |
|
false |
--log.level |
|
info |
--log.format |
|
logfmt |
--web.listen-address |
|
:9630 |
--web.config.file |
|
"" |
--web.telemetry-path |
PG_EXPORTER_TELEMETRY_PATH |
/metrics |
Connection URL Defaults
- If
--url / PG_EXPORTER_URL is not provided, pg_exporter falls back to a local-first default URL: postgresql:///?sslmode=disable.
- If
sslmode is not explicitly set in the URL, pg_exporter injects sslmode=disable by default.
- This is an intentional design choice for common on-host deployments (
pg_exporter and PostgreSQL/PgBouncer on the same machine), where loopback TLS adds overhead with little practical gain.
- If you need TLS for remote targets, provide
sslmode explicitly in the connection URL (for example: sslmode=require, verify-ca, verify-full).
API
PG Exporter provides a rich set of HTTP endpoints:
Here are pg_exporter REST APIs
# Fetch metrics (customizable)
curl localhost:9630/metrics
# Show version and build metadata
curl localhost:9630/version
# Reload configuration
curl -X POST localhost:9630/reload
# Explain configuration
curl localhost:9630/explain
# Print Statistics
curl localhost:9630/stat
# Aliveness health check (200 up, 503 down)
curl localhost:9630/up
curl localhost:9630/health
curl localhost:9630/liveness
curl localhost:9630/readiness
# traffic route health check
### 200 if not in recovery, 404 if in recovery, 503 if server is down
curl localhost:9630/primary
curl localhost:9630/leader
curl localhost:9630/master
curl localhost:9630/read-write
curl localhost:9630/rw
### 200 if in recovery, 404 if not in recovery, 503 if server is down
curl localhost:9630/replica
curl localhost:9630/standby
curl localhost:9630/slave
curl localhost:9630/read-only
curl localhost:9630/ro
### 200 if server is ready for read traffic (including primary), 503 if server is down
curl localhost:9630/read
Build
Use Go 1.27.4 or later, as declared in go.mod.
To build a static stand-alone binary for docker scratch
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o pg_exporter
Or download the latest prebuilt binaries from release pages.
We also have pre-packaged RPM / DEB packages in the Pigsty Infra Repo
Docker
You can find pre-built amd64/arm64 docker images here: pgsty/pg_exporter
Build a local development image from the canonical Dockerfile:
make docker
# Override the image repository when needed:
make docker DOCKER_REPO=example/pg_exporter
Multi-architecture release images are built by GoReleaser together with the other release artifacts.
Deployment
Redhat rpm and Debian/Ubuntu deb packages are made with nfpm for x86/arm64: