Database Configuration
SLOzy uses PostgreSQL 16+ as its primary data store and Redis 7+ for caching and ephemeral state.
Connection String
The backend builds a libpq-style connection string from individual env vars in internal/config/config.go:
func (c *Config) GetPostgresConnectionString() string {
return "host=" + c.PostgresHost +
" port=" + strconv.Itoa(c.PostgresPort) +
" dbname=" + c.PostgresDB +
" user=" + c.PostgresUser +
" password=" + c.PostgresPassword +
" sslmode=" + c.PostgresSSLMode
}Alternatively, the .env.production file supports a DATABASE_URL connection string format:
DATABASE_URL=postgres://postgres:postgres@postgres-service:5432/slozy_db?sslmode=requireChoose one approach — they are mutually exclusive in the current codebase.
Connection Pool
Fine-tune the pool based on your workload and available database connections.
| Variable | Default | Suggestion |
|---|---|---|
POSTGRES_MAX_OPEN_CONNS | 25 | 50-100 for production with moderate load |
POSTGRES_MAX_IDLE_CONNS | 10 | 10-25 — enough to handle bursts |
POSTGRES_CONN_MAX_LIFETIME | 1h | Keep at 1h to avoid stale connections |
POSTGRES_CONN_MAX_IDLETIME | 10m | 5-10m balances reuse and freshness |
SSL Mode
- Development:
disable - Production:
requireorverify-full - When using
verify-full, provide the CA certificate path via thePGSSLCERT/PGSSLKEYenv vars (or bake it into the Docker image).
Migrations
Migration SQL files live in migrations/ and follow the pattern {version}_{name}.{up|down}.sql:
migrations/
000001_organizations.up.sql
000001_organizations.down.sql
000002_teams.up.sql
000002_teams.down.sql
000003_users.up.sql
000003_users.down.sqlRun migrations through the Makefile or your CI pipeline:
make migrate-up
make migrate-downIn Docker Compose, migrations can be applied at container start by mounting the migrations/ directory to /docker-entrypoint-initdb.d.
Local Development
Use the docker-compose.yml file to spin up PostgreSQL and Redis:
docker-compose up -d postgres redisDefault credentials (postgres / postgres) are set in the compose file. Point your .env values to localhost:5432.
Redis
Redis stores:
- Session cache: JWT blacklist and user sessions (TTL:
8h) - SLO status cache: Recent SLO burn-rate data (TTL:
60s) - Prometheus query cache: Aggregated metric query results (TTL:
30s)
Redis is optional — the application degrades gracefully if Redis is unreachable (cache is bypassed).