{"record":{"id":"4b49b4f656f5a0be","repo":"neondatabase/neon","slug":"failed-to-parse-autovacuum-workers-count","errorCode":null,"errorMessage":"failed to parse autovacuum workers count: {}","messagePattern":"failed to parse autovacuum workers count: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compute_tools/src/monitor.rs","lineNumber":335,"sourceCode":"                    \"failed to get list of active logical replication subscriptions: {}\",\n                    e\n                ));\n            }\n        }\n\n        // Do not suspend compute if autovacuum is running\n        const AUTOVACUUM_COUNT_QUERY: &str =\n            \"select count(*) from pg_stat_activity where backend_type = 'autovacuum worker'\";\n        match cli.query_one(AUTOVACUUM_COUNT_QUERY, &[]) {\n            Ok(r) => match r.try_get::<&str, i64>(\"count\") {\n                Ok(num_workers) => {\n                    if num_workers > 0 {\n                        self.last_active = Some(Utc::now());\n                        return Ok(());\n                    };\n                }\n                Err(e) => {\n                    return Err(anyhow::anyhow!(\n                        \"failed to parse autovacuum workers count: {}\",\n                        e\n                    ));\n                }\n            },\n            Err(e) => {\n                return Err(anyhow::anyhow!(\n                    \"failed to get list of autovacuum workers: {}\",\n                    e\n                ));\n            }\n        }\n\n        Ok(())\n    }\n}\n\n// Hang on condition variable waiting until the compute status is `Running`.","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/compute_tools/src/monitor.rs#L317-L353","documentation":"The autovacuum-count query (`select count(*) from pg_stat_activity where backend_type = 'autovacuum worker'`) succeeded, but r.try_get::<&str, i64>(\"count\") failed - the 'count' column could not be converted to i64. Since count(*) is int8, this points at type/schema drift or a mangled row rather than a runtime value issue. The error aborts check() and is handled as downtime plus reconnect.","triggerScenarios":"try_get mismatch: 'count' column not of SQL type INT8, column absent, or a Postgres version/build whose count output type differs.","commonSituations":"Postgres major-version upgrades or patched builds changing system-view expression types; query edits that drop the 'count' alias without updating the Rust side.","solutions":["Cast explicitly in SQL: `count(*)::pg_catalog.bigint`","Read the inner FromSql error to see expected vs actual type","Keep the query and the try_get type in sync when modifying monitor queries","Cover monitor queries with integration tests against your shipped PG version"],"exampleFix":"// before\nconst AUTOVACUUM_COUNT_QUERY: &str =\n    \"select count(*) from pg_stat_activity where backend_type = 'autovacuum worker'\";\n\n// after\nconst AUTOVACUUM_COUNT_QUERY: &str =\n    \"select count(*)::pg_catalog.bigint from pg_stat_activity where backend_type = 'autovacuum worker'\";","handlingStrategy":"validation","validationCode":"// pin the wire type in SQL so try_get::<_, i64> cannot mismatch\nconst AUTOVACUUM_COUNT_QUERY: &str =\n    \"select count(*)::pg_catalog.bigint from pg_stat_activity where backend_type = 'autovacuum worker'\";","typeGuard":"fn count_is_int8(row: &postgres::Row, col: &str) -> bool {\n    row.columns()\n        .iter()\n        .any(|c| c.name() == col && *c.type_() == postgres::types::Type::INT8)\n}","tryCatchPattern":"match r.try_get::<&str, i64>(\"count\") {\n    Ok(n) => { /* use n */ }\n    Err(e) => warn!(\"autovacuum count unreadable, skipping: {e}\"), // non-fatal for the check\n}","preventionTips":["Cast count() to ::bigint whenever the Rust side reads i64","Keep SQL and try_get types in one place when editing monitor queries","Add tests for monitor queries per supported PG version"],"tags":["postgres","autovacuum","pg-stat-activity","type-conversion","rust"],"backgroundTag":"postgres-column-type-mismatch","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}