Skip to content

fix: report query_time in microseconds to match PgBouncer#952

Open
SAY-5 wants to merge 1 commit into
postgresml:mainfrom
SAY-5:fix/810-query-time-microseconds
Open

fix: report query_time in microseconds to match PgBouncer#952
SAY-5 wants to merge 1 commit into
postgresml:mainfrom
SAY-5:fix/810-query-time-microseconds

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 25, 2026

Fixes #810.

Problem

SHOW STATS reported total_query_time and avg_query_time in milliseconds while PgBouncer reports the same fields in microseconds. After a 1-second SELECT pg_sleep(1), PgCat showed total_query_time = 1001 while PgBouncer showed 1007496.

wait_time was already stored in microseconds (via as_micros() in pool.rs), so this was an inconsistency within PgCat itself as well.

Fix

Change the elapsed-time calculation in src/client.rs from .as_millis() to .as_micros() when calling server.stats().query(...). Update the parameter name in ServerStats::query() from milliseconds to microseconds to match.

Two files changed, three lines:

  • src/client.rs: as_millis() -> as_micros()
  • src/stats/server.rs: rename milliseconds param to microseconds

Verification

  • cargo build passes with no new warnings
  • cargo clippy passes (pre-existing unrelated warning only)
  • cargo fmt produces no changes
  • Stash-revert check: reverting to as_millis() would restore the wrong-unit values; the commit restores the correct behaviour

SHOW STATS reported total_query_time and avg_query_time in milliseconds
while PgBouncer reports the same fields in microseconds. Change the
elapsed duration calculation from as_millis() to as_micros() so the
values are consistent with PgBouncer and with wait_time, which was
already stored in microseconds.

Fixes postgresml#810

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Durations reported by SHOW STATS are in milliseconds, not microseconds

1 participant