Environment variables starting with
PG_EXPORTER_ will be overwritten by the corresponding CLI flag if given.Data Source Variables
These variables configure the PostgreSQL connection. See Data Source Configuration for detailed examples.Complete connection string including credentials. Supports both URI format (
postgresql://user:pass@host/db) and key=value format (host=localhost user=postgres). Takes precedence over all other data source variables.Example: postgresql://postgres:password@localhost:5432/postgres?sslmode=disableDatabase hostname and connection parameters without credentials. Format:
hostname:port/database?optionsExample: localhost:5432/postgres?sslmode=disablePath to a file containing the DATA_SOURCE_URI value. Whitespace is trimmed.Example:
/run/secrets/db_uriDatabase username. Used with DATA_SOURCE_URI to construct the full connection string.Example:
postgres_exporterPath to a file containing the username. Whitespace is trimmed. Takes precedence over DATA_SOURCE_USER.Example:
/run/secrets/db_userDatabase password. Used with DATA_SOURCE_URI to construct the full connection string.Example:
secure_passwordPath to a file containing the password. Whitespace is trimmed. Takes precedence over DATA_SOURCE_PASS. Recommended for security.Example:
/run/secrets/db_passwordExporter Behavior Variables
These variables control how the exporter operates and what metrics it collects.HTTP path where metrics are exposed.CLI Flag:
--web.telemetry-pathWhen
true, only metrics from custom queries are exported (requires PG_EXPORTER_EXTEND_QUERY_PATH). Built-in collector metrics are disabled.CLI Flag: --disable-default-metricsValues: true, falseWhen
true, disables scraping of pg_settings metrics.CLI Flag: --disable-settings-metricsValues: true, falseTimeout for collecting statistics from PostgreSQL. When reached, the database connection is dropped to prevent connection pool exhaustion. Must be greater than 1ms.CLI Flag:
--collection-timeoutExample: 30s, 2m, 500msPrefix for all exported metrics. Change this to avoid metric name conflicts.CLI Flag:
--metric-prefixExample: postgres, pgsqlDeprecated Variables
DEPRECATED: Automatically discover and monitor all databases on the server.CLI Flag:
--auto-discover-databasesDeprecation Note: Use service discovery in Prometheus instead of database auto-discovery in the exporter.DEPRECATED: Comma-separated list of database names to exclude when
PG_EXPORTER_AUTO_DISCOVER_DATABASES is enabled.CLI Flag: --exclude-databasesExample: template0,template1,postgresDEPRECATED: Comma-separated list of database names to exclusively include when
PG_EXPORTER_AUTO_DISCOVER_DATABASES is enabled. Empty means all (minus excludes).CLI Flag: --include-databasesExample: app_db,analytics_dbDEPRECATED: Path to YAML file with custom queries. Use built-in collectors instead, or see sql_exporter for generic SQL monitoring.CLI Flag:
--extend.query-pathExample: /etc/postgres_exporter/queries.yamlDEPRECATED: Comma-separated list of label=value pairs to add to all metrics.CLI Flag:
--constantLabelsExample: environment=production,region=us-east-1Configuration Examples
- Docker Compose
- Kubernetes
- systemd
- Shell Script
docker-compose.yml
Precedence with CLI Flags
When both environment variables and CLI flags are set:CLI flags always take precedence over environment variables.
Validation
Verify your environment variables are set correctly:Next Steps
Command-Line Flags
Explore CLI flags that override environment variables
Data Source Configuration
Deep dive into connection string formats