Skip to main content
The PostgreSQL Server Exporter can be configured through multiple methods to suit different deployment scenarios.

Configuration Methods

The exporter supports three primary configuration approaches:

Environment Variables

Configure using environment variables for containerized deployments

Command-Line Flags

Use flags for traditional server deployments

Configuration File

Define auth modules and multi-target support via YAML

Configuration File Location

The exporter loads its configuration from a YAML file specified by the --config.file flag. The default location is postgres_exporter.yml in the current working directory.
postgres_exporter --config.file=/etc/postgres_exporter/config.yml

Precedence Order

When the same setting is configured in multiple places, the following precedence applies (highest to lowest):
1

Command-line flags

Flags passed directly to the exporter have the highest priority
2

Environment variables

Environment variables prefixed with PG_EXPORTER_ override defaults
3

Configuration file

Settings in the YAML configuration file
4

Default values

Built-in defaults when no configuration is provided
Environment variables starting with PG_EXPORTER_ will be overwritten by the corresponding CLI flag if given.

Basic Configuration Example

Here’s a minimal configuration to get started:
export DATA_SOURCE_URI="localhost:5432/postgres?sslmode=disable"
export DATA_SOURCE_USER="postgres"
export DATA_SOURCE_PASS="password"
export PG_EXPORTER_WEB_TELEMETRY_PATH="/metrics"

./postgres_exporter

Configuration File Structure

The YAML configuration file supports the following top-level sections:

auth_modules

Defines authentication modules for multi-target monitoring. See Authentication Modules for details.
auth_modules:
  prod_db:
    type: userpass
    userpass:
      username: monitoring_user
      password: secure_password
    options:
      sslmode: require
      connect_timeout: "10"

Quick Start Guides

Data Source Configuration

Configure database connection strings and DSN formats

Environment Variables

Complete reference of all environment variables

Security Considerations

Never commit configuration files containing passwords to version control. Use file-based secrets or environment variables from a secure store.

Using File-Based Secrets

For enhanced security, store sensitive values in files:
echo "my_secure_password" > /run/secrets/db_password
chmod 600 /run/secrets/db_password

export DATA_SOURCE_PASS_FILE="/run/secrets/db_password"
./postgres_exporter
The exporter supports _FILE variants for:
  • DATA_SOURCE_USER_FILE
  • DATA_SOURCE_PASS_FILE
  • DATA_SOURCE_URI_FILE
When running in a container, the process runs with uid/gid 65534. Ensure file permissions allow this user to read secret files.

Next Steps

Configure Data Source

Set up your PostgreSQL connection

Explore Flags

Browse all available command-line options

Build docs developers (and LLMs) love