{"record":{"id":"30f2a9df311d54fc","repo":"nautechsystems/nautilus_trader","slug":"failed-to-set-synchronous-commit-off-e","errorCode":null,"errorMessage":"Failed to set synchronous_commit OFF: {e}","messagePattern":"Failed to set synchronous_commit OFF: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1410,"sourceCode":"    /// - `synchronous_commit` = OFF\n    /// - `work_mem` increased for bulk operations\n    ///\n    /// When disabled (false), restores default safe settings:\n    /// - `synchronous_commit` = ON (data safety)\n    /// - `work_mem` back to default\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operations fail.\n    pub async fn toggle_perf_sync_settings(&self, enable: bool) -> anyhow::Result<()> {\n        if enable {\n            log::debug!(\"Enabling performance sync settings for bulk operations\");\n\n            // Set synchronous_commit to OFF for maximum write performance\n            sqlx::query(\"SET synchronous_commit = OFF\")\n                .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","sourceCodeStart":1392,"sourceCodeEnd":1428,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1392-L1428","documentation":"Wraps failure of the `SET synchronous_commit = OFF` statement used to enable bulk-write performance during sync operations. It is a session-level Postgres tuning command, so failure means the database rejected the setting or the connection broke.","triggerScenarios":"Calling the performance-toggling method (database.rs) with enabled=true when the SET statement errors: insufficient privileges (non-superuser/session settings restrictions), connection loss, or a pooled connection in a broken/aborted transaction state.","commonSituations":"Connecting as a role without permission to change synchronous_commit; managed Postgres (RDS/Cloud SQL) with restricted settings; sync start while the pool has stale idle connections that were dropped by the server or a firewall.","solutions":["Read the embedded `{e}`; for permission errors (42501) grant the role the needed setting rights or run sync as a privileged user.","Verify connectivity and that the pool returns healthy connections before starting bulk sync.","If the server forbids changing synchronous_commit, skip the optimization path (run with default settings).","On managed databases, check provider docs for which SET commands are permitted."],"exampleFix":"// before: fail sync when tuning cannot be applied\nsqlx::query(\"SET synchronous_commit = OFF\").execute(&self.pool).await\n    .map_err(|e| anyhow::anyhow!(\"Failed to set synchronous_commit OFF: {e}\"))?;\n// after: treat tuning as best-effort\nif let Err(e) = sqlx::query(\"SET synchronous_commit = OFF\").execute(&self.pool).await {\n    log::warn!(\"bulk sync tuning unavailable, continuing with defaults: {e}\");\n}","handlingStrategy":"try-catch","validationCode":"// probe whether the session may change the setting before enabling bulk mode\nlet allowed: Result<(String,), _> = sqlx::query_as(\"SHOW synchronous_commit\").fetch_one(&pool).await;\nif allowed.is_err() { log::warn!(\"session tuning unavailable; bulk sync will use defaults\"); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = self.set_performance_mode(true).await {\n    log::warn!(\"performance mode unavailable, continuing safely: {e}\");\n    // proceed without bulk optimizations rather than aborting sync\n}","preventionTips":["Grant the sync role permission for session-level SET commands.","Check managed-Postgres (RDS/Cloud SQL) restrictions on synchronous_commit.","Health-check pooled connections before starting bulk operations.","Make tuning best-effort, never a hard prerequisite for syncing."],"tags":["database","postgres","performance-tuning","permissions"],"backgroundTag":"permission-denied","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"}