{"record":{"id":"371346879db0e5d8","repo":"block/buzz","slug":"audit-db-connection-failed-e","errorCode":null,"errorMessage":"Audit DB connection failed: {e}","messagePattern":"Audit DB connection failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/buzz-relay/src/main.rs","lineNumber":443,"sourceCode":"                        \"Failed to bootstrap relay owner (non-fatal, membership not required): {e}\"\n                    );\n                }\n            }\n        }\n    }\n\n    // NIP-33: backfill d_tag for any existing parameterized replaceable events\n    // that predate the column addition. Idempotent — no-ops when fully populated.\n    match db.backfill_d_tags().await {\n        Ok(0) => {}\n        Ok(n) => info!(\"Backfilled d_tag for {n} NIP-33 events\"),\n        Err(e) => error!(\"Failed to backfill d_tags: {e}\"),\n    }\n\n    let (audit, audit_metrics_pool) = if config.audit_enabled {\n        let audit_pool = connect_audit_pool(&db_config)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Audit DB connection failed: {e}\"))?;\n        info!(\"Audit service ready\");\n        let metrics_pool = audit_pool.clone();\n        (Some(AuditService::new(audit_pool)), Some(metrics_pool))\n    } else {\n        info!(\"Audit logging disabled by BUZZ_AUDIT_ENABLED\");\n        (None, None)\n    };\n\n    let redis_pool = {\n        let mut cfg = deadpool_redis::Config::from_url(&config.redis_url);\n        cfg.pool = Some(deadpool_redis::PoolConfig::new(config.redis_pool_size));\n        cfg.create_pool(Some(deadpool_redis::Runtime::Tokio1))\n            .map_err(|e| anyhow::anyhow!(\"Redis pool creation failed: {e}\"))?\n    };\n    let redis_health_pool = redis_pool.clone(); // cheap Arc clone — shared with readiness handler\n    let pubsub = Arc::new(\n        PubSubManager::new(&config.redis_url, redis_pool)\n            .await","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/block/buzz/blob/ef2aa1ae38fadcc0bc22b8bf6ed96b35933146be/crates/buzz-relay/src/main.rs#L425-L461","documentation":"Fatal startup error: BUZZ_AUDIT_ENABLED=true, and the small dedicated audit pool (max 5 connections) failed to connect to config.database_url. The audit service keeps a hash-chain audit log in Postgres; without it the relay refuses to start because the operator has explicitly required auditing.","triggerScenarios":"Postgres became unreachable between the main Db::new() connect and this one (e.g. failover, connection limit hit), or the URL allows the main pool's lazy dials but not additional eager connections (max_connections exhausted).","commonSituations":"Postgres connection budget consumed by other services so the extra eager pool connect fails; Postgres restarting mid-boot; audit enabled in an environment whose DB user has a hard connection cap.","solutions":["Verify connectivity again with the same URL: psql \"$DATABASE_URL\" -c 'select 1'","Check Postgres max_connections headroom — the audit pool adds up to 5 more eager connections","Restart once Postgres is stable","If auditing is not actually required in this environment, set BUZZ_AUDIT_ENABLED=false (then audit is skipped at boot)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Reserve headroom: keep (relay pools + audit 5 + search 1) below Postgres\n# max_connections; check current usage before deploy:\npsql \"$DATABASE_URL\" -c 'show max_connections; select count(*) from pg_stat_activity;'","typeGuard":null,"tryCatchPattern":"// Retry startup with backoff — the eager audit connect only fails when\n// Postgres is momentarily unavailable or connections are exhausted.","preventionTips":["Account for the audit pool's 5 eager connections in DB sizing","If audit is optional in a tier, leave BUZZ_AUDIT_ENABLED=false there"],"tags":["postgres","audit","connection","startup","buzz-relay"],"backgroundTag":"database-connection-failed","analyzedSha":"ef2aa1ae38fadcc0bc22b8bf6ed96b35933146be","analyzedAt":"2026-09-20T04:38:17.397Z","contentChangedAt":"2026-09-20T04:38:17.397Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}