{"record":{"id":"cc0b9a5b42ed3b89","repo":"neondatabase/neon","slug":"could-not-query-active-time","errorCode":null,"errorMessage":"could not query active_time: {}","messagePattern":"could not query active_time: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compute_tools/src/monitor.rs","lineNumber":423,"sourceCode":"fn get_database_stats(cli: &mut Client) -> anyhow::Result<(f64, i64)> {\n    // Filter out `postgres` database as `compute_ctl` and other monitoring tools\n    // like `postgres_exporter` use it to query Postgres statistics.\n    // Use explicit 8 bytes type casts to match Rust types.\n    let stats = cli.query_one(\n        \"SELECT pg_catalog.coalesce(pg_catalog.sum(active_time), 0.0)::pg_catalog.float8 AS total_active_time,\n            pg_catalog.coalesce(pg_catalog.sum(sessions), 0)::pg_catalog.bigint AS total_sessions\n        FROM pg_catalog.pg_stat_database\n        WHERE datname NOT IN (\n                'postgres',\n                'template0',\n                'template1'\n            );\",\n        &[],\n    );\n    let stats = match stats {\n        Ok(stats) => stats,\n        Err(e) => {\n            return Err(anyhow::anyhow!(\"could not query active_time: {}\", e));\n        }\n    };\n\n    let active_time: f64 = match stats.try_get(\"total_active_time\") {\n        Ok(active_time) => active_time,\n        Err(e) => return Err(anyhow::anyhow!(\"could not get total_active_time: {}\", e)),\n    };\n\n    let sessions: i64 = match stats.try_get(\"total_sessions\") {\n        Ok(sessions) => sessions,\n        Err(e) => return Err(anyhow::anyhow!(\"could not get total_sessions: {}\", e)),\n    };\n\n    Ok((active_time, sessions))\n}\n\n// Figure out the most recent state change time across all client backends.\n// If there is currently active backend, timestamp will be `Utc::now()`.","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/compute_tools/src/monitor.rs#L405-L441","documentation":"get_database_stats(), the helper behind the experimental activity monitor, runs query_one over pg_stat_database (sum of active_time and sessions for non-system databases). This error means that query returned Err - despite the message mentioning only active_time, it covers the whole statistics query. The caller wraps it further as 'could not get database statistics' and the monitor reports downtime then reconnects.","triggerScenarios":"query_one on pg_stat_database fails: dead connection (is_closed() can miss it), statement timeout, or Postgres restarting/crashing while the monitor polls every 500ms.","commonSituations":"Compute suspend/resume racing the monitor; overloaded computes timing out on catalog views; development environments with frequently killed Postgres processes.","solutions":["Read the appended tokio_postgres error to identify connection vs timeout vs server failure","Confirm the compute reached Running state and Postgres accepts connections","Accept transient single errors - the monitor reconnects automatically","For recurring timeouts, tune statement_timeout or reduce load"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"let stats = match cli.query_one(GET_DB_STATS_SQL, &[]) {\n    Ok(row) => row,\n    Err(e) => {\n        error!(\"could not query active_time: {e}\");\n        client = conf.connect(NoTls);\n        continue; // next monitor tick\n    }\n};","preventionTips":["Only enable the experimental statistics monitor on computes that reach Running cleanly","Accept transient failures; alert on streaks via the downtime metrics","Keep statement_timeout generous enough for pg_stat_database aggregates"],"tags":["postgres","pg-stat-database","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"}