vacuum_utils
vacuum_utils · SQL functions for inspecting VACUUM and ANALYZE thresholds and activity and for invoking table maintenance.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100695 | vacuum_utils | vacuum_utils | 0.1.0 | ADMIN | PostgreSQL | SQL |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
vacuum_utils provides SQL helpers for estimating autovacuum/analyze thresholds, reading the last maintenance time and count, toggling per-table autovacuum, and running ANALYZE. The canonical function name diff_to_autovaccum intentionally retains upstream’s misspelling.
Core Workflow
The inspection helpers read pg_stat_user_tables, pg_class.reltuples, and the current global autovacuum settings. The mutating helpers execute ALTER TABLE or ANALYZE with the caller’s privileges.
Object Index
diff_to_autovaccum(schema, table)estimates remaining dead tuples before the global vacuum threshold.get_table_vacuum_thresholdandget_table_analyze_thresholdcalculate global-setting-based thresholds.last_vacuum_count,last_autovacuum_count,last_analyze_count, andlast_autoanalyze_countreturn adatetext_and_intcomposite.disable_autovacuumandenable_autovacuumchange the table’sautovacuum_enabledreloption.execute_analyzerunsANALYZEfor the named table.
Operational Notes
The upstream README explicitly says version 0.1.0 has known bugs. Although the control file says relocatable, the SQL script creates and uses a fixed vacuum_utils schema. The threshold calculations use current global GUCs and do not account for per-table storage parameters, inserts-based triggers, wraparound vacuum, partition behavior, or planner-estimate staleness; treat results as rough diagnostics only.
Do not grant the mutating functions to untrusted roles. Their dynamic SQL concatenates schema and table arguments without identifier quoting, creating syntax and SQL-injection risk, and the functions run with invoker privileges. Use only administrator-supplied simple identifiers, confirm the target table separately, and prefer native catalog queries plus safely quoted ALTER TABLE/ANALYZE statements in production automation.