Docs Releases GitHub 简体中文

DECLARATIVE POSTGRESQL METRICS EXPORTER

pg_exporter

PostgreSQL observability, expressed in SQL.Declarative collectors · dynamic planning · native Prometheus metrics

One binary plus YAML and SQL covers PostgreSQL 10–19+ and PgBouncer 1.8–1.25+, selecting query branches by server version, role, and installed extensions.

$ PG_EXPORTER_URL='postgres://monitor@localhost/postgres' pg_exporter

CURRENT SURFACE

Useful by Default, Precise When Customized

QUICK START

Connect, Start, Scrape

Install v1.4.1 for your platform, then verify the complete database-to-Prometheus path in three actions.

sudo apt install -y pg-exporter
PG_EXPORTER_URL='postgres://monitor@localhost/postgres' pg_exporter
curl -fsS localhost:9630/metrics

WHY PG EXPORTER

Make SQL the Observability Interface

Collector logic lives in configuration; the runtime handles discovery, planning, caching, timeouts, and Prometheus encoding.

DECLARATIVE

YAML + SQL

  • Add or revise metrics without changing Go code
  • Declare GAUGE, COUNTER, HISTOGRAM, and LABEL mappings
  • Control cost with TTL and per-collector timeouts

DYNAMIC PLAN

Plan for the Target

  • Match version, recovery role, database, and user
  • Check extensions, schemas, and custom predicates
  • Explain every planning verdict through /explain

OPERATING MODEL

Clear Boundaries from Connection to Series

01 · PLAN

Discover the Target, Build a Plan

  • Connect to PostgreSQL or PgBouncer
  • Read version, role, extension, and schema facts
  • Select one compatible branch for each collector

02 · COLLECT

Execute Concurrently, Encode Consistently

  • Default collectors cover identity, replication, WAL, I/O, locks, and relations
  • A non-fatal collector failure preserves other successful results
  • Exporter self-metrics and database metrics remain distinct