Created
August 18, 2022 18:42
-
-
Save krisiye/59428720a6d3f328d50db670c92b9a9b to your computer and use it in GitHub Desktop.
Useful queries to evaluate database level stats
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
-- Cache hit ratio. | |
-- Sweet spot here are values close to 100 which also means all necessary data were read from shared buffers. | |
-- values near 90 or lower show that postgres read from disk time to time. | |
SELECT | |
round(100 * sum(blks_hit) / sum(blks_hit + blks_read), 3) as cache_hit_ratio | |
FROM pg_stat_database; | |
-- estimate commit ratio and detect errors | |
-- values that are closer to 100 mean that you database has very few errors. | |
SELECT | |
datname, 100 * xact_commit / (xact_commit + xact_rollback) as commit_ratio | |
FROM pg_stat_database WHERE (xact_commit + xact_rollback) > 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment