{"record":{"id":"6085c40a2c6240a9","repo":"nautechsystems/nautilus_trader","slug":"failed-to-set-synchronous-commit-on-e","errorCode":null,"errorMessage":"Failed to set synchronous_commit ON: {e}","messagePattern":"Failed to set synchronous_commit ON: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1426,"sourceCode":"                .execute(&self.pool)\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to set synchronous_commit OFF: {e}\"))?;\n\n            // Increase work_mem for bulk operations\n            sqlx::query(\"SET work_mem = '256MB'\")\n                .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,","sourceCodeStart":1408,"sourceCodeEnd":1444,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1408-L1444","documentation":"Wraps failure of the `SET synchronous_commit = ON` statement used to restore safe durability settings after bulk sync completes. Failing here leaves the session possibly still in the unsafe OFF state, so it also signals that data-safety restoration did not complete.","triggerScenarios":"Calling the performance-toggling method with enabled=false when restoring defaults: connection lost after the bulk sync window (most common — long syncs often outlive idle timeouts), role lacks permission to SET, or the pooled connection was returned/recycled.","commonSituations":"Very long bulk syncs whose connection was dropped by an idle firewall/LB timeout, so the restore SET fails; switching database roles between enable and restore; pgbouncer transaction pooling discarding session-level SET state.","solutions":["Read the embedded `{e}`; on connection-closed errors reconnect and re-issue SET synchronous_commit = ON before other work.","Avoid transaction-pooling modes (pgbouncer transaction pool) that do not preserve session-level SETs.","Run restore inside a short window immediately after bulk writes, or issue periodic keepalives during long syncs.","Verify role permissions if the error is a privilege failure (42501)."],"exampleFix":"// before: restore assumed to run on the same live connection\nsqlx::query(\"SET synchronous_commit = ON\").execute(&self.pool).await\n    .map_err(|e| anyhow::anyhow!(\"Failed to set synchronous_commit ON: {e}\"))?;\n// after: verify connection health before restoring\nsqlx::query(\"SELECT 1\").execute(&self.pool).await?;\nsqlx::query(\"SET synchronous_commit = ON\").execute(&self.pool).await\n    .map_err(|e| anyhow::anyhow!(\"Failed to set synchronous_commit ON: {e}\"))?;","handlingStrategy":"retry","validationCode":"// verify the connection is alive before attempting to restore settings\nsqlx::query(\"SELECT 1\").execute(&pool).await\n    .map_err(|e| anyhow!(\"connection dead before settings restore: {e}\"))?;","typeGuard":null,"tryCatchPattern":"for attempt in 0..3 {\n    match sqlx::query(\"SET synchronous_commit = ON\").execute(&self.pool).await {\n        Ok(_) => break,\n        Err(e) if attempt == 2 => return Err(anyhow!(\"Failed to set synchronous_commit ON: {e}\")),\n        Err(_) => tokio::time::sleep(Duration::from_secs(2)).await,\n    }\n}","preventionTips":["Keepalives during long bulk syncs to survive idle timeouts.","Avoid pgbouncer transaction-pooling for sessions that use SET.","Always restore durability settings in a defer/close path that reconnects on failure.","Alert when restore fails: the session may remain in synchronous_commit=OFF."],"tags":["database","postgres","connection","performance-tuning"],"backgroundTag":"connection-refused","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}