{"record":{"id":"6f889a060f27f727","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-account-ids-e","errorCode":null,"errorMessage":"Failed to load account ids: {e}","messagePattern":"Failed to load account ids: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1224,"sourceCode":"    ///\n    /// # Errors\n    ///\n    /// Returns an error if loading events or SQL operations fail.\n    pub async fn load_accounts(pool: &PgPool) -> anyhow::Result<Vec<AccountAny>> {\n        let mut accounts: Vec<AccountAny> = Vec::new();\n        let account_ids: Vec<AccountId> = sqlx::query(\n            r#\"\n            SELECT DISTINCT account_id FROM \"account_event\"\n        \"#,\n        )\n        .fetch_all(pool)\n        .await\n        .map(|rows| {\n            rows.into_iter()\n                .map(|row| AccountId::from(row.get::<&str, _>(0)))\n                .collect()\n        })\n        .map_err(|e| anyhow::anyhow!(\"Failed to load account ids: {e}\"))?;\n        for id in account_ids {\n            let account = Self::load_account(pool, &id).await?;\n            if let Some(account) = account {\n                accounts.push(account);\n            }\n        }\n        Ok(accounts)\n    }\n\n    /// Inserts a `TradeTick` entry via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the SQL INSERT operation fails.\n    pub async fn add_trade(pool: &PgPool, trade: &TradeTick) -> anyhow::Result<()> {\n        sqlx::query(r#\"\n            INSERT INTO \"trade\" (\n                instrument_id, price, quantity, aggressor_side, venue_trade_id,","sourceCodeStart":1206,"sourceCodeEnd":1242,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1206-L1242","documentation":"This error wraps sqlx failures while querying the list of distinct account ids in `load_accounts`. The SELECT that returns account ids failed, so no accounts can be loaded. The underlying sqlx error is embedded in the message.","triggerScenarios":"Calling `load_accounts(pool)` when the database is unreachable, the backing table is missing (migrations not applied), the query times out, or the pool has no usable connections.","commonSituations":"Fresh environment where migrations were never run; wrong DSN/env config; Postgres restart mid-request; timeouts with many accounts.","solutions":["Confirm DB connectivity and correct DSN in the pool configuration","Run schema migrations so the account-event table exists","Inspect the wrapped sqlx error in `{e}` (undefined table, connection refused, timeout) and address it","Add retry with backoff for transient connection errors"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"sqlx::query(\"SELECT 1 FROM account_event LIMIT 1\").fetch_optional(pool).await.map_err(|e| anyhow::anyhow!(\"schema check: {e}\"))?;","typeGuard":null,"tryCatchPattern":"let ids = load_account_ids(pool).await?; // add backoff retry around this for transient errors\nfor attempt in 0..3 {\n    match load_accounts(pool).await { Ok(a) => break a, Err(e) if attempt == 2 => return Err(e), Err(_) => tokio::time::sleep(backoff).await }\n}","preventionTips":["Run migrations before first use","Configure sensible pool size and connect timeouts","Add retry/backoff for transient connection errors"],"tags":["database","sql","postgres"],"backgroundTag":"database-query-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}