Skip to main content
This page documents all command-line flags supported by postgres_exporter.

Usage

postgres_exporter [flags]
Flags can be specified in multiple ways:
# Long form with equals
postgres_exporter --web.telemetry-path=/custom-metrics

# Long form with space
postgres_exporter --web.telemetry-path /custom-metrics

# Using environment variables (for supported flags)
PG_EXPORTER_WEB_TELEMETRY_PATH=/custom-metrics postgres_exporter

Flag Categories

Configuration File

FlagTypeDefaultEnv VariableDescription
--config.filestringpostgres_exporter.yml-Path to the configuration file for auth modules

Web Server

FlagTypeDefaultEnv VariableDescription
--web.listen-addressstring:9187-Address to listen on for web interface and telemetry
--web.telemetry-pathstring/metricsPG_EXPORTER_WEB_TELEMETRY_PATHPath under which to expose metrics
--web.config.filestring--Path to TLS and/or basic authentication configuration file. See exporter-toolkit docs
--web.systemd-socketbooleanfalse-Use systemd socket activation listeners instead of port listeners (Linux only)

Metrics Configuration

FlagTypeDefaultEnv VariableDescription
--disable-default-metricsbooleanfalsePG_EXPORTER_DISABLE_DEFAULT_METRICSOnly use metrics from custom queries. Disables all built-in collectors
--disable-settings-metricsbooleanfalsePG_EXPORTER_DISABLE_SETTINGS_METRICSDo not scrape pg_settings metrics
--metric-prefixstringpgPG_EXPORTER_METRIC_PREFIXPrefix for all metrics (default is pg_)

Collection Settings

FlagTypeDefaultEnv VariableDescription
--collection-timeoutduration1mPG_EXPORTER_COLLECTION_TIMEOUTTimeout for collecting statistics when the database is slow. Minimum value is 1ms

Deprecated Flags

The following flags are deprecated and will be removed in a future release. They are maintained for backward compatibility only.
FlagTypeDefaultEnv VariableDescriptionReplacement
--auto-discover-databasesbooleanfalsePG_EXPORTER_AUTO_DISCOVER_DATABASESDynamically discover databases on the serverUse multi-target pattern instead
--exclude-databasesstring""PG_EXPORTER_EXCLUDE_DATABASESComma-separated list of databases to exclude when auto-discovery is enabledUse multi-target pattern instead
--include-databasesstring""PG_EXPORTER_INCLUDE_DATABASESComma-separated list of databases to include when auto-discovery is enabledUse multi-target pattern instead
--extend.query-pathstring""PG_EXPORTER_EXTEND_QUERY_PATHPath to custom queries YAML fileUse built-in collectors or sql_exporter
--constantLabelsstring""PG_EXPORTER_CONSTANT_LABELSComma-separated list of label=value pairs to add to all metricsUse relabeling in Prometheus

Utility Flags

FlagTypeDefaultDescription
--dumpmapsbooleanfalsePrint the internal metric maps and exit without running the exporter
--versionbooleanfalsePrint version information and exit
--help, -hbooleanfalseShow help information

Logging

These flags are provided by the Prometheus common library:
FlagTypeDefaultDescription
--log.levelstringinfoLog level: debug, info, warn, error
--log.formatstringlogfmtLog format: logfmt, json

Collector Flags

Each collector can be individually enabled or disabled using boolean flags. The format is --collector.<name> or --no-collector.<name>.

Enabled by Default

FlagDescription
--[no-]collector.databasePostgreSQL databases statistics from pg_database
--[no-]collector.locksLock statistics from pg_locks
--[no-]collector.replicationReplication statistics from pg_stat_replication
--[no-]collector.replication_slotReplication slot statistics from pg_replication_slots
--[no-]collector.rolesRole statistics from pg_roles
--[no-]collector.stat_bgwriterBackground writer statistics from pg_stat_bgwriter
--[no-]collector.stat_databaseDatabase statistics from pg_stat_database
--[no-]collector.stat_progress_vacuumVacuum progress from pg_stat_progress_vacuum (PG 13+)
--[no-]collector.stat_user_tablesUser table statistics from pg_stat_user_tables
--[no-]collector.statio_user_tablesUser table I/O statistics from pg_statio_user_tables
--[no-]collector.walWAL statistics from pg_wal or pg_xlog

Disabled by Default

FlagDescription
--[no-]collector.database_wraparoundTransaction ID wraparound monitoring from pg_database
--[no-]collector.long_running_transactionsLong-running transaction detection
--[no-]collector.postmasterPostmaster process uptime
--[no-]collector.process_idleIdle process statistics
--[no-]collector.stat_activity_autovacuumAutovacuum activity from pg_stat_activity
--[no-]collector.stat_checkpointerCheckpointer statistics from pg_stat_checkpointer (PG 17+)
--[no-]collector.stat_statementsQuery statistics from pg_stat_statements extension
--[no-]collector.stat_wal_receiverWAL receiver statistics from pg_stat_wal_receiver
--[no-]collector.statio_user_indexesUser index I/O statistics from pg_statio_user_indexes
--[no-]collector.xlog_locationTransaction log location (deprecated, use wal collector)
--[no-]collector.buffercache_summaryBuffer cache summary from pg_buffercache extension
Why some collectors are disabled by default:
  • High cardinality: stat_statements creates one time series per unique query
  • Performance overhead: Some collectors require expensive queries
  • Extension required: buffercache_summary requires pg_buffercache extension
  • Specific use cases: postmaster, process_idle are useful in specific scenarios

pg_stat_statements Flags

When the stat_statements collector is enabled, additional flags control its behavior:
FlagTypeDefaultDescription
--collector.stat_statements.include_querybooleanfalseInclude the full query text in metrics (increases cardinality)
--collector.stat_statements.query_lengthuint120Maximum length of query text to include
--collector.stat_statements.limituint100Maximum number of statements to return per scrape
--collector.stat_statements.exclude_databasesstring""Comma-separated list of databases to exclude from statement metrics
--collector.stat_statements.exclude_usersstring""Comma-separated list of users to exclude from statement metrics
Enabling pg_stat_statements with include_query can create extremely high cardinality. Use limit and exclude_* flags to control the number of time series created.

Examples

Basic Usage

# Use default settings
postgres_exporter

Custom Web Configuration

# Custom port and metrics path
postgres_exporter \
  --web.listen-address=:9188 \
  --web.telemetry-path=/custom-metrics

Enable Additional Collectors

# Enable commonly useful collectors
postgres_exporter \
  --collector.database_wraparound \
  --collector.long_running_transactions \
  --collector.postmaster

Disable Default Collectors

# Disable noisy collectors
postgres_exporter \
  --no-collector.stat_user_tables \
  --no-collector.statio_user_tables

Enable pg_stat_statements

# Enable with safety limits
postgres_exporter \
  --collector.stat_statements \
  --collector.stat_statements.limit=50 \
  --collector.stat_statements.query_length=80 \
  --collector.stat_statements.exclude_databases=postgres,template0,template1

Production Configuration

# Full production setup
postgres_exporter \
  --config.file=/etc/postgres_exporter/config.yml \
  --web.listen-address=:9187 \
  --web.config.file=/etc/postgres_exporter/web-config.yml \
  --collection-timeout=30s \
  --log.level=info \
  --log.format=json \
  --collector.database_wraparound \
  --collector.long_running_transactions \
  --no-collector.stat_user_tables

Debug Mode

# Enable debug logging
postgres_exporter \
  --log.level=debug \
  --log.format=logfmt

Dump Internal Metrics

# View metric definitions without running
postgres_exporter --dumpmaps

Flag Precedence

When the same configuration is specified in multiple ways, the precedence is:
  1. Command-line flags (highest priority)
  2. Environment variables (see [Environment Variables(../reference/environment-variables))
  3. Configuration file (for auth modules only)
  4. Default values (lowest priority)
Example:
# Environment variable sets path to /metrics
export PG_EXPORTER_WEB_TELEMETRY_PATH=/metrics

# Flag overrides environment variable
postgres_exporter --web.telemetry-path=/custom
# Result: metrics exposed at /custom

Boolean Flag Syntax

Boolean flags support multiple syntaxes:
# Enable a collector
postgres_exporter --collector.stat_statements
postgres_exporter --collector.stat_statements=true

# Disable a collector
postgres_exporter --no-collector.stat_statements
postgres_exporter --collector.stat_statements=false

Getting Help

# Show all flags with descriptions
postgres_exporter --help

# Show detailed help
postgres_exporter --help-long

# Show man-page style help
postgres_exporter --help-man

See Also

  • [Configuration File(../reference/configuration-file) - YAML configuration reference
  • [Environment Variables(../reference/environment-variables) - Environment variable reference
  • [Collectors(../guides/collectors) - Detailed collector documentation

Build docs developers (and LLMs) love