Repository navigation
fix(tool/postgres-list-database-stats): compute rollback_ratio_percent without the +1 bias - #4577
Open
beskvladimir-create wants to merge 2 commits into
Conversation
…t without the +1 bias
… against the returned counters
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the calculation of rollback_ratio_percent in the Postgres database statistics tool to avoid division-by-zero errors and remove the biased denominator (+ 1). It also adds a comprehensive integration test to verify that the rollback ratio is computed correctly. There are no review comments, and I have no feedback to provide.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
postgres-list-database-statscomputedrollback_ratio_percentasxact_rollback * 100.0 / (xact_commit + xact_rollback + 1). The+ 1guards against division by zero but is also applied to every non-zero denominator, so the reported share is always too low, and badly so for small counters: 1 commit and 1 rollback reports33.33instead of50.00, 0 commits and 5 rollbacks83.33instead of100.00(details in #4576).This change uses the same pattern as
cache_hit_ratio_percentin the same statement:0when there are no completed transactions, otherwiseround((xact_rollback * 100.0) / (xact_commit + xact_rollback), 2). No other column changes.Testing: I ran the full statement with this change on PostgreSQL 16.15 (with and without
include_templates, includingtemplate0with 0/0) and it returns the exact percentage. I also added a subtest toRunPostgresListDatabaseStatsTest(used by the postgres, alloydbpg, alloydbomni and cloudsqlpg integration tests): it connects to the fresh test database, rolls back one transaction, waits untilpg_stat_databaseshows it, invokeslist_database_statsfor that database and checksrollback_ratio_percentagainst thexact_commit/xact_rollbackvalues returned in the same row. With the small counters of a fresh database the old formula would not pass this check (in a psql run of the same steps the database had 1 commit and 1 rollback: 33.33 vs 50.00). I could not run the Go tests locally (my environment cannot download the Go 1.27 toolchain), so the Go test relies on CI.Security: no new input path; all parameters are bound exactly as before and the change only affects how two catalog counters are combined.
PR Checklist
!if this involve a breaking change (not breaking)🛠️ Fixes #4576