Overview
All database connection parameters can be read from environment variables. This is particularly useful for:- Security: Keep sensitive connection details out of version control
- Flexibility: Use different configurations for development, staging, and production
- Container/Cloud deployments: Easily configure databases using platform environment variables (Kubernetes secrets, Docker env vars, etc.)
Supported Databases
Environment variable support is available for:- ClickHouse
- PostgreSQL
- MySQL
- Redshift
- BigQuery
How It Works
For any database connection parameter, you can use the_var suffix to reference an environment variable instead of hardcoding the value.
Example: ClickHouse
Before (hardcoded):Supported Fields by Database Type
ClickHouse
host/host_var- Connection URLuser/user_var- Usernamepassword/password_var- Passworddatabase/database_var- Database name
PostgreSQL
host/host_var- Hostname (default:localhost)port/port_var- Port number (default:5432)user/user_var- Username (default:postgres)password/password_var- Passworddatabase/database_var- Database name (default:postgres)
MySQL
host/host_var- Hostname (default:localhost)port/port_var- Port number (default:3306)user/user_var- Username (default:root)password/password_var- Passworddatabase/database_var- Database name (default:mysql)
Redshift
host/host_var- Hostname (default:localhost)port/port_var- Port number (default:5439)user/user_var- Username (default:awsuser)password/password_var- Passworddatabase/database_var- Database name (default:dev)
BigQuery
key_path/key_path_var- Path to service account key file
Configuration Patterns
1. Full Environment Variable Configuration
All connection details from environment:2. Mixed Configuration
Combine hardcoded and environment variables:3. Minimal Configuration with Defaults
Only specify what differs from defaults:- host:
localhost(default) - port:
5432(default) - user:
postgres(default) - password: from
POSTGRES_PASSWORDenv var - database:
myapp(specified)
Usage with Docker Compose
Usage with Kubernetes
Create a Secret:Best Practices
- Never commit passwords: Use
password_varfor all password fields - Use
.envfiles locally: Keep a.env.examplein your repo with dummy values - Separate configs per environment: Use different config files for dev/staging/prod
- Document required env vars: List all required environment variables in your README
- Provide defaults: Use the default values feature for common settings like
localhost
Migration from Hardcoded Values
To migrate existing configurations:- Identify sensitive values (passwords, hosts, etc.)
- Replace hardcoded values with
_varreferences - Set up environment variables in your deployment
- Test the configuration before deploying to production