Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pg_exporter

> 数据库
Open source

Advanced PostgreSQL & Pgbouncer Metrics Exporter for Prometheus

356 stars0 likes0 views
WebsiteGitHub

About

Advanced PostgreSQL & Pgbouncer Metrics Exporter for Prometheus

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. It provides 600+ metrics and ~3K time series per instance, covers everything you'll need for PostgreSQL observability.

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
  • Full Coverage: Monitor PostgreSQL (10-19+) and pgBouncer (1.8-1.25+) in a single exporter
  • 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

Also support PG 9.x with legacy config bundle.


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:

bash
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

…

Parameters could be given via command-line args or environment variables.

CLI Arg Environment Variable Default Value
--url PG_EXPORTER_URL 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
--fail-fast PG_EXPORTER_FAIL_FAST false
--exclude-database PG_EXPORTER_EXCLUDE_DATABASE
--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

…

Build

To build a static stand-alone binary for docker scratch

bash
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:

bash
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:

  • /usr/bin/pg_exporter: the pg_exporter binary.
  • /etc/pg_exporter.yml: the config file
  • /usr/lib/systemd/system/pg_exporter.service: systemd service file
  • /etc/default/pg_exporter: systemd service envs & options

Which is also available on Pigsty's Infra Repo.


Collectors

Configs lie in the core of pg_exporter. Actually, this project contains more lines of YAML than go.

  • A monolith battery-included config file: pg_exporter.yml
  • Separated metrics definition in config/
  • Example of how to write a config file: doc.yml
  • Authoritative Histogram design: docs/design/histogram.md
  • Legacy config bundle for PostgreSQL 9.1 - 9.6: legacy/ (legacy/README.md)

Current pg_exporter ships 58 collector definition files in config/. They are merged into pg_exporter.yml by make conf.

File Collector namespace(s) Scope / requirement
0000-doc.yml config reference YAML schema and collector authoring guide; not an installed collector
0110-pg.yml pg PostgreSQL basic information, with primary and replica branches
0120-pg_meta.yml pg_meta PostgreSQL cluster metadata; PG13+ includes primary_conninfo
0130-pg_setting.yml pg_setting Shared PostgreSQL settings and capacity limits
0210-pg_repl.yml pg_repl Replication sender statistics
0220-pg_sync_standby.yml pg_sync_standby Synchronous standby status
0230-pg_downstream.yml pg_downstream Downstream replication client counts
0240-pg_slot.yml pg_slot Replication slots; PG16+ branches also work on standbys, and PG17+ recognizes the PG19 idle_timeout invalidation reason
0250-pg_recv.yml pg_recv Replica WAL receiver metrics; PG13+ branch recognizes the PG19 connecting status
0260-pg_sub.yml pg_sub Subscription stats; PG19 branch covers table/sequence sync errors and logical replication conflict counters
0270-pg_origin.yml pg_origin Replication origin status; disabled by default and may need extra privileges
0300-pg_io.yml pg_io pg_stat_io metrics for PG16+, with PG18+ branch
0310-pg_size.yml pg_size Database, WAL, and log size metrics
0320-pg_archiver.yml pg_archiver Archiver process statistics
0330-pg_bgwriter.yml pg_bgwriter Background writer statistics, with PG17+ branch
0331-pg_checkpointer.yml pg_checkpointer Checkpointer statistics, with PG18+ num_done and slru_written metrics
0340-pg_ssl.yml pg_ssl SSL client connection counts

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gomonitoringpg-exporterpgbouncerpostgres

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库