multica-ai/multica · critical
connect to database: %w
Error message
connect to database: %w
What it means
Returned by the backfill_codex_usage_cache tool when pgxpool.New fails to construct a connection pool from the database URL. This is a configuration/connection-string failure (bad DSN, unreachable host, bad TLS settings), not a query failure — note the separate 'ping database' error covers connectivity after pool creation. The DSN comes from DATABASE_URL, defaulting to postgres://multica:multica@localhost:5432/multica?sslmode=disable.
Source
Thrown at server/cmd/backfill_codex_usage_cache/main.go:91
flag.BoolVar(&cfg.rebuildRollup, "rebuild-rollup", true, "after --execute, call rollup_task_usage_hourly_window for the update window")
flag.Parse()
now := time.Now().UTC()
if err := cfg.parseAndValidate(now); err != nil {
return err
}
dbURL := os.Getenv("DATABASE_URL")
if dbURL == "" {
dbURL = "postgres://multica:multica@localhost:5432/multica?sslmode=disable"
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
pool, err := pgxpool.New(ctx, dbURL)
if err != nil {
return fmt.Errorf("connect to database: %w", err)
}
defer pool.Close()
if err := pool.Ping(ctx); err != nil {
return fmt.Errorf("ping database: %w", err)
}
rows, total, err := loadDryRunSummary(ctx, pool, cfg)
if err != nil {
return err
}
logSummary(cfg, rows, total)
if total.Rows == 0 {
slog.Info("no eligible Codex task_usage rows found")
return nil
}
if !cfg.execute {
slog.Info("dry-run complete; review the summary, then re-run with --execute to apply the backfill")View on GitHub (pinned to 2c0912b6ec)
Solutions
- Set DATABASE_URL to a valid DSN for the target database and re-run (e.g. postgres://user:pass@host:5432/multica?sslmode=require).
- Verify the postgres host/port are reachable from where the tool runs (psql '$DATABASE_URL' -c 'select 1').
- Check DSN syntax: scheme, percent-encoded special characters in the password, and correct sslmode for the server.
Example fix
# before $ DATABASE_URL='postgres://multica:multica@localhost:5432/multica' ./backfill_codex_usage_cache --cutoff ... # connect to database: ... # after $ export DATABASE_URL='postgres://multica:p%40ss@db.internal:5432/multica?sslmode=require' $ ./backfill_codex_usage_cache --cutoff 2026-01-01T00:00:00Z
Defensive patterns
Strategy: validation
Validate before calling
# Validate the DSN before running the backfill
[ -n "$DATABASE_URL" ] || { echo 'DATABASE_URL is unset'; exit 1; }
psql "$DATABASE_URL" -c 'select 1' >/dev/null || { echo 'DSN unreachable'; exit 1; } Prevention
- Always export DATABASE_URL explicitly; never rely on the localhost default in shared environments.
- Percent-encode special characters in the DSN password.
- Prove connectivity with psql using the exact same URL before launching the tool.
When it happens
Trigger: Running the backfill binary with DATABASE_URL unset while no local postgres is listening on 5432; a DSN with a syntax error, wrong port, or sslmode mismatch against the server; unresolvable hostname.
Common situations: Running the tool on a workstation instead of the deployment environment; forgetting to export DATABASE_URL in the shell or systemd unit; rotating the DB password so the embedded credentials are stale; managed postgres requiring sslmode=require while the default DSN disables SSL.
Related errors
- ping database: %w
- acquire advisory lock %d: %w
- rebuild hourly rollup for update window %s..%s: %w
- read database clock: %w
- acquire advisory-lock connection: %w
AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15).
Data as JSON: /api/errors/224e31d8a87052a0.
Report an issue: GitHub.