multica-ai/multica · critical
ping database: %w
Error message
ping database: %w
What it means
Returned when the pool was created but pool.Ping(ctx) fails — the tool's first actual round-trip to postgres. It means the DSN parsed and the pool object exists, but the server rejected or never answered the connection: wrong credentials, database does not exist, pg_hba rejection, TLS failure, or network drop. Distinguish it from 'connect to database', which is a DSN/pool-construction failure.
Source
Thrown at server/cmd/backfill_codex_usage_cache/main.go:96
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")
return nil
}
lockConn, err := pool.Acquire(ctx)
if err != nil {View on GitHub (pinned to 2c0912b6ec)
Solutions
- Confirm credentials and database name in DATABASE_URL by connecting with psql using the same DSN.
- Match sslmode to the server (try sslmode=require for managed postgres).
- If pg_hba rejects the client, run the tool from an allowed host or have the DBA allow it.
- Re-run — transient network blips between pool creation and ping are possible.
Example fix
# before export DATABASE_URL='postgres://multica:multica@localhost:5432/multica?sslmode=disable' ./backfill_codex_usage_cache --cutoff ... # ping database: ... (auth failed / no ssl) # after export DATABASE_URL='postgres://multica:multica@db.internal:5432/multica?sslmode=require' ./backfill_codex_usage_cache --cutoff 2026-01-01T00:00:00Z
Defensive patterns
Strategy: retry
Validate before calling
# Pre-flight the exact DSN, including TLS mode PGCONNECT_TIMEOUT=5 psql "$DATABASE_URL" -c 'select 1' || echo 'fix DSN: credentials, dbname, or sslmode'
Prevention
- Match sslmode to the server policy (require for most managed postgres).
- Rotate DSNs together with database credentials so they never go stale.
- Treat auth failures as configuration bugs — retrying will not help until the DSN is fixed.
When it happens
Trigger: Valid-format DSN with wrong password/user (auth failure), non-existent database name, pg_hba.conf denying the client IP, server requiring TLS the client didn't negotiate, or a firewall dropping the connection after DNS resolution.
Common situations: Credentials rotated after the DSN was written; pointing at the right host but the wrong database name; running the backfill from CI/NAT whose IP is not in pg_hba; managed postgres enforcing SSL while sslmode=disable.
Related errors
- connect to database: %w
- acquire advisory lock %d: %w
- rebuild hourly rollup for update window %s..%s: %w
- acquire advisory-lock connection: %w
- load dry-run summary: %w
AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15).
Data as JSON: /api/errors/eaf6fa2013cdac21.
Report an issue: GitHub.