Multi-target support is currently in BETA and may require changes in future releases. Feedback is welcome.
The PostgreSQL Server Exporter supports the multi-target pattern , allowing you to monitor multiple PostgreSQL instances from a single exporter instance.
When to Use Multi-target
Multi-target functionality is optional and intended for specific use cases:
Monitoring SaaS-managed PostgreSQL services where you cannot install the exporter as a sidecar
Centralized monitoring of many PostgreSQL instances
Dynamic PostgreSQL targets that change frequently
For most deployments, running the exporter as a sidecar (one per PostgreSQL instance) is simpler and recommended.
How It Works
Instead of configuring a single data source via environment variables, the exporter exposes a /probe endpoint that accepts target information as URL parameters.
Basic Usage
Send HTTP requests to the /probe endpoint with the target DSN:
curl "http://localhost:9187/probe?target=postgres-server1:5432"
The target parameter should contain the DSN (Data Source Name) of the PostgreSQL instance to scrape.
Authentication Modules
To avoid putting sensitive credentials in URLs, configure authentication modules in the exporter’s configuration file.
Configuration File
Create a postgres_exporter.yml file with auth module definitions:
auth_modules :
production :
type : userpass
userpass :
username : postgres_exporter
password : your_secure_password
options :
sslmode : require
connect_timeout : "10"
development :
type : userpass
userpass :
username : dev_monitor
password : dev_password
options :
sslmode : disable
Using Auth Modules
Reference the auth module in the probe request:
curl "http://localhost:9187/probe?target=server1:5432&auth_module=production"
The exporter will:
Look up the production auth module
Apply the username and password
Add any configured options to the DSN
Connect to server1:5432 and collect metrics
Prometheus Configuration
Configure Prometheus to scrape multiple targets through the exporter using relabeling:
scrape_configs :
- job_name : 'postgres'
static_configs :
- targets :
- server1:5432
- server2:5432
- server3:5432
metrics_path : /probe
params :
auth_module : [ production ]
relabel_configs :
# Pass the target as a URL parameter
- source_labels : [ __address__ ]
target_label : __param_target
# Use the target as the instance label
- source_labels : [ __param_target ]
target_label : instance
# Replace the scrape address with the exporter's address
- target_label : __address__
replacement : localhost:9187
How Relabeling Works
First relabel : Takes the target address (e.g., server1:5432) and sets it as the target URL parameter
Second relabel : Copies the target to the instance label so metrics show the correct PostgreSQL instance
Third relabel : Changes the scrape address to the exporter’s actual location
Multiple Environments
You can scrape different PostgreSQL environments with different auth modules:
scrape_configs :
- job_name : 'postgres-prod'
static_configs :
- targets :
- prod-db1:5432
- prod-db2:5432
metrics_path : /probe
params :
auth_module : [ production ]
relabel_configs :
- source_labels : [ __address__ ]
target_label : __param_target
- source_labels : [ __param_target ]
target_label : instance
- target_label : __address__
replacement : localhost:9187
- job_name : 'postgres-dev'
static_configs :
- targets :
- dev-db1:5432
metrics_path : /probe
params :
auth_module : [ development ]
relabel_configs :
- source_labels : [ __address__ ]
target_label : __param_target
- source_labels : [ __param_target ]
target_label : instance
- target_label : __address__
replacement : localhost:9187
Starting the Exporter
Start the exporter with the configuration file:
./postgres_exporter --config.file=postgres_exporter.yml
Or with Docker:
docker run -p 9187:9187 \
-v $( pwd ) /postgres_exporter.yml:/etc/postgres_exporter.yml \
quay.io/prometheuscommunity/postgres-exporter \
--config.file=/etc/postgres_exporter.yml
Limitations
Currently, only userpass authentication type is supported
Each scrape creates a new connection to the target database
Connection pooling is not available in multi-target mode
See the Performance Tuning guide for optimization tips
Next Steps
Security Best Practices Learn how to secure your exporter deployment
Performance Tuning Optimize collection timeouts and collector selection