fix(trigger): add size threshold to table bloat trigger#34
Open
kqr wants to merge 1 commit into
Open
Conversation
Small tables that are frequently rewritten can trivially have > 50 % table bloat even though the absolute size of the bloat is just a few kB. This is the normal, stable, desirable condition for such tables. In those cases, the suggested VACUUM FULL is an incorrect response. The common solution to this is to add a size threshold to the table bloat trigger. There's no strict guidance for such a threshold, and different sources use different thresholds: - pgexperts/pgx_scripts needs 10 MB of table bloat to trigger by default - keithf4/pg_bloat_check lists example triggers of 10 MB and 1 GB - Heroku's documentation suggests a threshold of 100 MB This commit is written with a conservative threshold to catch obvious false alarms without deviating too far from the function's earlier behaviour.
kqr
commented
Jul 22, 2026
| q | ||
| where | ||
| bloat_pct > 50.0 | ||
| and schemaname not like all(array['information_schema', 'pg_catalog', 'pg_toast', 'pg_temp%']) |
Author
There was a problem hiding this comment.
I adjusted the indentation of this filter so it's aligned with the rest of the where clause expression. Not strictly necessary, but I figured I might as well when I'm in there anyway.
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.
Small tables that are frequently rewritten can trivially have > 50 % table bloat even though the absolute size of the bloat is just a few kB. This is the normal, stable, desirable condition for such tables. In those cases, the suggested VACUUM FULL is an incorrect response.
The common solution to this is to add a size threshold to the table bloat trigger. There's no strict guidance for such a threshold, and different sources use different thresholds:
This commit is written with a conservative threshold to catch obvious false alarms without deviating too far from the function's earlier behaviour.
Type of Change
Related Issues
n/a
Testing
PostgreSQL Version Compatibility
Has this code been tested against the following PostgreSQL versions?
Testing notes:
Very small change and little scope for what could go wrong. It seems to work as expected.
Managed Database Platforms
Has this code been deployed and tested on the following platforms?
Platform-specific notes:
Unfortunately not been able to do any testing on managed platforms.
Additional Notes