The Postgres App Server now supports reading database connection details from multiple sources without requiring command-line arguments.
The server reads database configuration in the following priority order:
- Command line argument (
--db-url) - Highest priority - Config file (
--config) - Medium priority - Environment variables - Lowest priority
Set one of these environment variables:
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/adk_db"export POSTGRES_URL="postgresql://postgres:postgres@localhost:5432/adk_db"
# OR
export POSTGRESQL_URL="postgresql://postgres:postgres@localhost:5432/adk_db"
# OR
export DB_URL="postgresql://postgres:postgres@localhost:5432/adk_db"export DBURL="localhost:5432/adk_db"
export DBUSER="postgres"
export DBPASSWORD="postgres"Create a .env file in the project root:
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/adk_dbThen load it (if using python-dotenv):
source .env # Or use python-dotenv to load automaticallyCreate a YAML or JSON config file:
production:
database:
url: "postgresql://postgres:postgres@localhost:5432/adk_db"
development:
database:
url: "postgresql://postgres:postgres@localhost:5432/adk_db_dev"{
"production": {
"database": {
"url": "postgresql://postgres:postgres@localhost:5432/adk_db"
}
},
"development": {
"database": {
"url": "postgresql://postgres:postgres@localhost:5432/adk_db_dev"
}
}
}The config file also supports these formats:
# Direct root-level key
db_url: "postgresql://postgres:postgres@localhost:5432/adk_db"# Root-level database section
database:
url: "postgresql://postgres:postgres@localhost:5432/adk_db"python -m google.adk.server.postgres_app_server \
--port 8000 \
--config config.yaml \
--environment productionIf you need to override config or env vars:
python -m google.adk.server.postgres_app_server \
--port 8000 \
--db-url "postgresql://postgres:postgres@localhost:5432/adk_db"# Set environment variable
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/adk_db"
# Run server (no --db-url needed!)
python -m google.adk.server.postgres_app_server --port 8000python -m google.adk.server.postgres_app_server \
--port 8000 \
--config config.yaml \
--environment productioncat > .env << EOF
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/adk_db
ADURL=https://your-api-gateway-url.com
ADU=your-username
ADP=your-password
REDBUS_ADG_MODEL=40
EOFsource .env # Or export them manuallypython -m google.adk.server.postgres_app_server --port 8000The VS Code launch configuration has been updated to use environment variables. Set DATABASE_URL in your environment or .env file, and it will be picked up automatically.
If no database URL is found, you'll see:
Database URL not found. Please provide one of:
- Command line: --db-url "postgresql://..."
- Config file: --config config.yaml
- Environment variable: DATABASE_URL, POSTGRES_URL, DB_URL, or DBURL/DBUSER/DBPASSWORD
-
Never commit credentials to version control
- Add
.envto.gitignore - Use environment variables in production
- Use secret management services for production
- Add
-
Use config files for different environments
config.production.yamlconfig.development.yaml- Keep config files out of version control
-
Prefer environment variables
- Easier to manage in containers/Kubernetes
- No risk of committing secrets
- Works well with CI/CD pipelines