{"record":{"id":"781fe44a2e2dc872","repo":"neondatabase/neon","slug":"could-not-query-backends","errorCode":null,"errorMessage":"could not query backends: {}","messagePattern":"could not query backends: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compute_tools/src/monitor.rs","lineNumber":492,"sourceCode":"                        Err(e) => {\n                            info!(\"cannot parse backend state_change DateTime: {}\", e);\n                            continue;\n                        }\n                    }\n                } else {\n                    // Found non-idle backend, so the last activity is NOW.\n                    // Return immediately, no need to check other backends.\n                    return Ok(Some(Utc::now()));\n                }\n            }\n\n            // Get idle backend `state_change` with the max timestamp.\n            if let Some(last) = idle_backs.iter().max() {\n                last_active = Some(*last);\n            }\n        }\n        Err(e) => {\n            return Err(anyhow::anyhow!(\"could not query backends: {}\", e));\n        }\n    }\n\n    Ok(last_active)\n}\n\n/// Launch a separate compute monitor thread and return its `JoinHandle`.\npub fn launch_monitor(compute: &Arc<ComputeNode>) -> thread::JoinHandle<()> {\n    let compute = Arc::clone(compute);\n    let experimental = compute.has_feature(ComputeFeature::ActivityMonitorExperimental);\n    let now = Utc::now();\n    let mut monitor = ComputeMonitor {\n        compute,\n        last_active: None,\n        last_checked: now,\n        last_up: now,\n        active_time: None,\n        sessions: None,","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/compute_tools/src/monitor.rs#L474-L510","documentation":"get_backends_state_change() SELECTs state and a formatted state_change timestamp FROM pg_stat_activity for client backends (excluding the monitor's own pid and cloud_admin). This error means cli.query() itself returned Err, so the idle-timestamp computation could not run. It flows out of check() where the monitor logs it, counts downtime, and reconnects.","triggerScenarios":"The pg_stat_activity query fails: connection closed mid-poll, statement timeout, Postgres restarting, or server error while iterating backends.","commonSituations":"Monitor polling during suspend/resume or crash/restart of Postgres; timeouts under heavy backend churn; transient transport breakage inside the compute container.","solutions":["Read the nested error for cause and SQLSTATE","Rely on monitor self-healing for one-off failures; it reconnects each 500ms tick","If continuous, examine Postgres logs and connectivity between compute_ctl and the server","Alert on consecutive monitor errors rather than individual occurrences"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"let backends = match cli.query(BACKENDS_SQL, &[]) {\n    Ok(rows) => rows,\n    Err(e) => {\n        error!(\"could not query backends: {e}\");\n        client = conf.connect(NoTls);\n        continue;\n    }\n};","preventionTips":["Retry transient pg_stat_activity failures on the next monitor tick","Alert on consecutive errors, not individual ones","Verify Postgres health when the error repeats rapidly"],"tags":["postgres","pg-stat-activity","monitoring","rust","connection"],"backgroundTag":"postgres-query-failed","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}