{"record":{"id":"224e31d8a87052a0","repo":"multica-ai/multica","slug":"connect-to-database-w","errorCode":null,"errorMessage":"connect to database: %w","messagePattern":"connect to database: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/cmd/backfill_codex_usage_cache/main.go","lineNumber":91,"sourceCode":"\tflag.BoolVar(&cfg.rebuildRollup, \"rebuild-rollup\", true, \"after --execute, call rollup_task_usage_hourly_window for the update window\")\n\tflag.Parse()\n\n\tnow := time.Now().UTC()\n\tif err := cfg.parseAndValidate(now); err != nil {\n\t\treturn err\n\t}\n\n\tdbURL := os.Getenv(\"DATABASE_URL\")\n\tif dbURL == \"\" {\n\t\tdbURL = \"postgres://multica:multica@localhost:5432/multica?sslmode=disable\"\n\t}\n\n\tctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)\n\tdefer stop()\n\n\tpool, err := pgxpool.New(ctx, dbURL)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"connect to database: %w\", err)\n\t}\n\tdefer pool.Close()\n\n\tif err := pool.Ping(ctx); err != nil {\n\t\treturn fmt.Errorf(\"ping database: %w\", err)\n\t}\n\n\trows, total, err := loadDryRunSummary(ctx, pool, cfg)\n\tif err != nil {\n\t\treturn err\n\t}\n\tlogSummary(cfg, rows, total)\n\tif total.Rows == 0 {\n\t\tslog.Info(\"no eligible Codex task_usage rows found\")\n\t\treturn nil\n\t}\n\tif !cfg.execute {\n\t\tslog.Info(\"dry-run complete; review the summary, then re-run with --execute to apply the backfill\")","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/backfill_codex_usage_cache/main.go#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\n$ DATABASE_URL='postgres://multica:multica@localhost:5432/multica' ./backfill_codex_usage_cache --cutoff ...\n# connect to database: ...\n\n# after\n$ export DATABASE_URL='postgres://multica:p%40ss@db.internal:5432/multica?sslmode=require'\n$ ./backfill_codex_usage_cache --cutoff 2026-01-01T00:00:00Z","handlingStrategy":"validation","validationCode":"# Validate the DSN before running the backfill\n[ -n \"$DATABASE_URL\" ] || { echo 'DATABASE_URL is unset'; exit 1; }\npsql \"$DATABASE_URL\" -c 'select 1' >/dev/null || { echo 'DSN unreachable'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["database","connection","backfill","postgres","environment"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}