{"record":{"id":"73b9f81a50cdf073","repo":"nautechsystems/nautilus_trader","slug":"failed-to-reset-work-mem-e","errorCode":null,"errorMessage":"Failed to reset work_mem: {e}","messagePattern":"Failed to reset work_mem: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1432,"sourceCode":"                .execute(&self.pool)\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to set work_mem: {e}\"))?;\n\n            log::debug!(\"Performance settings enabled: synchronous_commit=OFF, work_mem=256MB\");\n        } else {\n            log::debug!(\"Restoring default safe database performance settings\");\n\n            // Restore synchronous_commit to ON for data safety\n            sqlx::query(\"SET synchronous_commit = ON\")\n                .execute(&self.pool)\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to set synchronous_commit ON: {e}\"))?;\n\n            // Reset work_mem to default\n            sqlx::query(\"RESET work_mem\")\n                .execute(&self.pool)\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to reset work_mem: {e}\"))?;\n        }\n\n        Ok(())\n    }\n\n    /// Saves the checkpoint block number indicating the last completed pool synchronization for a specific DEX.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.\n    pub async fn update_dex_last_synced_block(\n        &self,\n        chain_id: u32,\n        dex: &DexType,\n        block_number: u64,\n    ) -> anyhow::Result<()> {\n        sqlx::query(\n            \"","sourceCodeStart":1414,"sourceCodeEnd":1450,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1414-L1450","documentation":"Wraps a sqlx error raised while executing `RESET work_mem` on the PostgreSQL connection pool. This library call runs after a large analytical query that temporarily raised `work_mem` via `SET LOCAL`/`SET`, and this step restores the session default. If the reset fails, the session may keep an inflated work_mem, risking memory pressure on subsequent queries.","triggerScenarios":"The `RESET work_mem` statement fails when executing `set_session_work_mem`-style cleanup: pool connections dropped mid-operation, the connection returning the error (e.g. server restarting, connection broken), or a superuser-only setting being reset on a restricted session in some managed setups.","commonSituations":"Postgres restarted or failed over between the SET and RESET; connection pooled and closed by the server (idle timeout); network blip between app and database; running against a managed Postgres (RDS/Cloud SQL) that restricts parameter changes.","solutions":["Check database connectivity and pool health; ensure the Postgres server was not restarted mid-operation","Log the underlying sqlx error (`{e}`) to identify whether it is a connection error vs a permission error","Wrap the reset in a best-effort match that logs instead of failing the whole sync, since the following queries still work","Verify the user role is allowed to RESET work_mem on managed Postgres services"],"exampleFix":"// before\n.map_err(|e| anyhow::anyhow!(\"Failed to reset work_mem: {e}\"))?;\n// after\nif let Err(e) = sqlx::query(\"RESET work_mem\").execute(&self.pool).await {\n    tracing::warn!(\"Failed to reset work_mem: {e}\");\n}","handlingStrategy":"try-catch","validationCode":"// Verify DB connectivity before session-tuning\nsqlx::query(\"SELECT 1\").execute(&pool).await?;","typeGuard":null,"tryCatchPattern":"match sqlx::query(\"RESET work_mem\").execute(&pool).await {\n    Ok(_) => {}\n    Err(e) => tracing::warn!(\"work_mem reset failed (non-fatal): {e}\"),\n}","preventionTips":["Treat session-parameter cleanup as best-effort; log rather than propagate","Monitor Postgres restarts and idle connection timeouts","Test against managed Postgres which may restrict parameter changes"],"tags":["database","postgresql","sqlx","session-state"],"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"}