block/buzz · critical · anyhow::Error

Audit DB connection failed: {e}

Error message

Audit DB connection failed: {e}

What it means

When BUZZ_AUDIT_ENABLED=true, a small dedicated Postgres pool (max 5 connections, min 1) is opened for the hash-chain audit log. A connection failure here aborts startup with the sqlx error — the relay will not run with a broken audit trail. It uses the same DATABASE_URL as the main pool, so causes overlap with the primary DB connection error.

Source

Thrown at crates/buzz-relay/src/main.rs:361

            }
        }
    }

    // NIP-33: backfill d_tag for any existing parameterized replaceable events
    // that predate the column addition. Idempotent — no-ops when fully populated.
    match db.backfill_d_tags().await {
        Ok(0) => {}
        Ok(n) => info!("Backfilled d_tag for {n} NIP-33 events"),
        Err(e) => error!("Failed to backfill d_tags: {e}"),
    }

    let audit = if config.audit_enabled {
        let audit_pool = sqlx::postgres::PgPoolOptions::new()
            .max_connections(5)
            .min_connections(1)
            .connect(&config.database_url)
            .await
            .map_err(|e| anyhow::anyhow!("Audit DB connection failed: {e}"))?;
        info!("Audit service ready");
        Some(AuditService::new(audit_pool))
    } else {
        info!("Audit logging disabled by BUZZ_AUDIT_ENABLED");
        None
    };

    let redis_pool = {
        let mut cfg = deadpool_redis::Config::from_url(&config.redis_url);
        cfg.pool = Some(deadpool_redis::PoolConfig::new(config.redis_pool_size));
        cfg.create_pool(Some(deadpool_redis::Runtime::Tokio1))
            .map_err(|e| anyhow::anyhow!("Redis pool creation failed: {e}"))?
    };
    let redis_health_pool = redis_pool.clone(); // cheap Arc clone — shared with readiness handler
    let pubsub = Arc::new(
        PubSubManager::new(&config.redis_url, redis_pool)
            .await
            .map_err(|e| anyhow::anyhow!("PubSub init failed: {e}"))?,

View on GitHub (pinned to f956e6fe06)

Solutions

  1. Verify DATABASE_URL connectivity: `psql "$DATABASE_URL" -c 'select 1'`
  2. Raise the Postgres connection limit or lower db_pool_size — the audit pool adds up to 5 more
  3. If auditing is not required in this environment, set BUZZ_AUDIT_ENABLED=false
Defensive patterns

Strategy: retry

Validate before calling

# Same URL as the main pool; verify once before boot.
psql "$DATABASE_URL" -c 'select 1' || { echo 'audit DB unreachable'; exit 1; }

Try / catch

relay:
  restart: on-failure:5

Prevention

When it happens

Trigger: Same DATABASE_URL connectivity/auth problems as the main pool, or the audit pool's extra connections push the account past its connection limit.

Common situations: Audit newly enabled in an environment with a tight connection quota; Postgres briefly unavailable when the relay pod starts; per-user limits on managed Postgres.

Related errors


AI-assisted analysis of block/buzz@f956e6fe06 (2026-08-16). Data as JSON: /api/errors/371346879db0e5d8. Report an issue: GitHub.