From 116286f80f5c55c22179df77d3f0cdb9277a7a04 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 30 Jun 2026 13:47:24 +0800 Subject: [PATCH] fix(database): cast count(*)::int in get_db_status to match i32 field count(*) returns bigint (int8) in PostgreSQL, but the result was read as i32 via conn_row.get(0). tokio-postgres's FromSql rejects an int8 column, so get_db_status panicked at runtime with 'error deserializing column 0' (HTTP 500). Cast count(*)::int to int4, matching the adjacent setting::int column and the total_connections/max_connections i32 struct fields. No other queries in the file are affected: reltuples is already ::bigint -> i64, size columns are native bigint -> i64, and system_status.rs reads its count(*) as i64 correctly. --- src/api/database/status.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/database/status.rs b/src/api/database/status.rs index c98762f..a66a3cd 100644 --- a/src/api/database/status.rs +++ b/src/api/database/status.rs @@ -89,10 +89,12 @@ pub async fn get_db_status() -> Result { .map_err(AppError::query)? .get(0); - // 当前库连接数 + 全局最大连接数 + // 当前库连接数 + 全局最大连接数。 + // count(*) 原生返回 bigint(int8),与下方 setting::int 一并显式转 int4, + // 以匹配 total_connections/max_connections 的 i32 类型(否则 FromSql 反序列化失败)。 let conn_row = client .query_one( - "SELECT count(*), \ + "SELECT count(*)::int, \ (SELECT setting::int FROM pg_settings WHERE name = 'max_connections') \ FROM pg_stat_activity WHERE datname = current_database()", &[],