The postgres_exporter is a Prometheus exporter written in Go that collects and exposes metrics from PostgreSQL database servers. It enables monitoring of PostgreSQL instances by converting internal database statistics into Prometheus-compatible metrics that can be scraped and visualized in monitoring systems.
The exporter supports PostgreSQL versions 13 through 18 as verified by its CI testing. It is distributed as a Docker container image and can be deployed either as a sidecar alongside individual PostgreSQL instances or as a centralized service using the multi-target pattern. The multi-target functionality, currently in beta, allows a single exporter instance to monitor multiple PostgreSQL targets by accepting HTTP requests to the /probe endpoint with target DSN parameters, making it suitable for monitoring SaaS-managed PostgreSQL services where sidecar deployment is not feasible.
The exporter provides extensive configurability through command-line flags and environment variables. It includes numerous collector modules that can be individually enabled or disabled, covering database statistics, replication status, transaction activity, WAL archiving, background writer statistics, table and index I/O metrics, and statement-level query statistics. Key collectors enabled by default include database metrics, locks, replication, replication slots, settings, statement activity, archiver statistics, background writer metrics, database statistics, vacuum progress, replication statistics, and user table statistics. Optional collectors disabled by default include database wraparound detection, long-running transaction tracking, postmaster metrics, idle process detection, autovacuum activity, checkpoint statistics, WAL receiver status, index I/O metrics, WAL metrics, and xlog location tracking.
Configuration is managed through a YAML file that supports auth_modules for defining preset authentication credentials, allowing sensitive connection information to be kept out of URLs when using the multi-target endpoint. The exporter accepts data source configuration through multiple environment variables including DATA_SOURCE_NAME, DATA_SOURCE_URI, and file-based variants for usernames and passwords, supporting secure credential management through mounted files rather than environment variables.
The repository shares contributors with microsoft/vscode, keycloak/keycloak, and microsoft/typescript, indicating cross-project collaboration within the broader open-source ecosystem.
The exporter includes advanced features such as configurable collection timeouts to prevent connection exhaustion when databases respond slowly, support for custom queries through external YAML files, metric prefix customization, and flexible logging with both logfmt and JSON output formats. It can be deployed with systemd socket activation on Linux systems and supports TLS and basic authentication through web configuration files.