Skip to content

PG Exporter 1.4 Documentation

Advanced PostgreSQL & pgBouncer Metrics Exporter for Prometheus

Monitor PostgreSQL with 600+ metrics, declarative configuration, and dynamic planning.

Get Started | GitHub | Live Demo


Features

FeatureDescription
Comprehensive Metrics600+ metrics cover nearly every statistics view in PostgreSQL (10-19+) and pgBouncer (1.8-1.25+)
Declarative CollectorsDefine each metric in a YAML collector with a SQL query and execution conditions. Add, change, or remove metrics without code changes
Dynamic PlanningSelect each collector branch for a target by version, primary/replica role, installed extensions, and tags
Auto-DiscoveryDiscover and scrape each database in an instance. The datname label identifies the database
Health Check APIsUse /up, /primary, and /replica as load-balancer probes to route primary/replica traffic
Smart CachingCache each collector by TTL. Frequent probes and scrapes do not cause an equal number of database queries
Snapshot HistogramsUse the HISTOGRAM column type to aggregate SQL snapshots into classic Prometheus histogram distributions
Extension AwareNative support for pg_stat_statements, pg_wait_sampling, citus, and timescaledb
Production ReadyUsed in production on 12K+ cores for 6+ years

Version Info

  • Current stable release: v1.4.1
  • Default config support: PostgreSQL 10-19+
  • Legacy config support: PostgreSQL 9.1-9.6 via the legacy/ config bundle
  • pgBouncer support: 1.8-1.25+

See Release Notes for the full history.


Design Rationale

pg_exporter uses these principles for production deployments:

  • Local connections: if no URL is specified, use postgresql:///?sslmode=disable for a database on the same host.
  • Declarative collection: use YAML collector definitions to control metric behavior with ttl, timeout, tags, and fatal.
  • Dynamic planning: select the collector branch at runtime from the server version, role, extensions, and tags.
  • Operation during failure: startup is non-blocking by default. HTTP endpoints start even if the database is temporarily unavailable.
  • Hot reload: use POST / GET /reload or SIGHUP to reload. Non-Windows platforms also support SIGUSR1.
  • Separate probes from traffic: health endpoints use cached background probes. Each request does not need a database query.
  • Protect management endpoints: /reload, /explain, and /stat expose runtime and configuration details. In production, protect them with --web.config.file or keep them internal.

Installation

Select an installation method for your infrastructure:

Docker
docker run -d --name pg_exporter -p 9630:9630 -e PG_EXPORTER_URL="postgres://user:pass@host:5432/postgres" pgsty/pg_exporter:latest
YUM
# RPM-based systems
sudo tee /etc/yum.repos.d/pigsty-infra.repo > /dev/null <<-'EOF'
[pigsty-infra]
name=Pigsty Infra for $basearch
baseurl=https://repo.pigsty.io/yum/infra/$basearch
enabled = 1
gpgcheck = 0
module_hotfixes=1
EOF

sudo yum makecache;
sudo yum install -y pg_exporter
APT
sudo tee /etc/apt/sources.list.d/pigsty-infra.list > /dev/null <<EOF
deb [trusted=yes] https://repo.pigsty.io/apt/infra generic main
EOF

sudo apt update;
sudo apt install -y pg-exporter
Binary
VERSION=$(curl -fsSL https://api.github.com/repos/pgsty/pg_exporter/releases/latest | sed -n 's/.*"tag_name": "v\([^"]*\)".*/\1/p')
wget "https://github.com/pgsty/pg_exporter/releases/download/v${VERSION}/pg_exporter-${VERSION}.linux-amd64.tar.gz"
mkdir -p "pg_exporter-${VERSION}.linux-amd64"
tar -xf "pg_exporter-${VERSION}.linux-amd64.tar.gz" -C "pg_exporter-${VERSION}.linux-amd64"
sudo install "pg_exporter-${VERSION}.linux-amd64/pg_exporter" /usr/bin/
sudo install "pg_exporter-${VERSION}.linux-amd64/pg_exporter.yml" /etc/pg_exporter.yml
Source
# Build from source
git clone https://github.com/pgsty/pg_exporter.git
cd pg_exporter
make build

Quick Start

Follow Getting Started to start PG Exporter:

# Minimal startup with the local-first default URL
pg_exporter

# Or point to a specific target
PG_EXPORTER_URL='postgres://user:pass@localhost:5432/postgres' pg_exporter

# Access metrics
curl http://localhost:9630/metrics

# Reload configuration online (POST recommended)
curl -X POST http://localhost:9630/reload

Documentation


Live Demo

Open the PG Exporter demo: https://g.pgsty.com

The demo monitors real PostgreSQL clusters with PG Exporter. It includes:

  • Real-time metrics visualization with Grafana
  • Multiple PostgreSQL versions and configurations
  • Extension-specific metrics and monitoring
  • Complete observability stack powered by Pigsty

Community & Support

  • GitHub - Source code, issues, and contributions
  • Discussions - Ask questions and share experiences
  • Pigsty - Complete PostgreSQL Distro with PG Exporter

License

PG Exporter is open-source software licensed under the Apache License 2.0.

Copyright 2018-2026 © Ruohang Feng / [email protected]

Get pg_exporter running and see PostgreSQL metrics in Prometheus within ten minutes

Production deployment — connection & credentials, systemd / Docker / Kubernetes, auto-discovery and alerting

Was this page helpful?