Connection Methods
The exporter supports multiple environment variables for configuring database connections, with different precedence levels.Precedence Order
The exporter checks for data sources in the following order:DATA_SOURCE_USER_FILE + DATA_SOURCE_PASS_FILE
File-based secrets for username and password (recommended for security)
The
DATA_SOURCE_NAME variable always wins to maintain backward compatibility. If set, all other configuration methods are ignored.DATA_SOURCE_NAME
The legacy all-in-one connection string format. Accepts both URI and key=value formats.Complete connection string including username and password. Supports both PostgreSQL URI format and key=value pairs.
URI Format
Key=Value Format
Unix Socket Connection
For local connections using Unix sockets:Multiple Databases
You can monitor multiple PostgreSQL instances by providing a comma-separated list:Split Format (Recommended)
For better security, split the connection details into separate components:DATA_SOURCE_URI
Hostname and connection parameters without username or password.
hostname:port/database?options
URI Format Examples
URI Format Examples
DATA_SOURCE_USER
Database username for authentication.
DATA_SOURCE_PASS
Database password for authentication.
File-Based Secrets (Most Secure)
Store sensitive credentials in files to avoid exposing them in environment variables or process listings.DATA_SOURCE_USER_FILE
Path to a file containing the database username.
DATA_SOURCE_PASS_FILE
Path to a file containing the database password.
The exporter trims whitespace from file contents, so trailing newlines won’t cause issues.
DATA_SOURCE_URI_FILE
Path to a file containing the DATA_SOURCE_URI value.
Complete Examples
- Docker with Files
- Kubernetes Secret
- Systemd Service
The container runs as uid/gid 65534. Ensure mounted files are readable by this user.
DSN Format Reference
The exporter uses the github.com/lib/pq library for PostgreSQL connections.Supported URL Schemes
postgresql://(preferred)postgres://(alias)
Common Connection Parameters
SSL connection mode:
disable, require, verify-ca, verify-fullMaximum wait for connection, in seconds. Zero means no timeout.
Path to client certificate file for SSL connections
Path to client private key file for SSL connections
Path to root certificate file for SSL verification
Application name to report to PostgreSQL
Example with All Parameters
Verifying Your Connection
Test your connection configuration:Troubleshooting
Connection refused
Connection refused
- Verify PostgreSQL is running and listening on the specified host/port
- Check firewall rules allow connections from the exporter
- Ensure
listen_addressesinpostgresql.confincludes the exporter’s IP
Authentication failed
Authentication failed
- Verify username and password are correct
- Check
pg_hba.confallows connections from the exporter’s host - Ensure the user has necessary permissions (see Running as Non-Superuser)
SSL/TLS errors
SSL/TLS errors
- Check
sslmodeparameter matches your server’s SSL configuration - Verify certificate paths are correct and files are readable
- Try
sslmode=disableto test without SSL (not for production)
File permission errors
File permission errors
- Ensure secret files are readable by the exporter process
- In Docker, the process runs as uid/gid 65534
- Check with:
ls -l /path/to/secret/file
Next Steps
Authentication Modules
Configure multi-target monitoring with auth modules
Environment Variables
Explore all available environment variables