postgresqlvacuum
This is an old revision of the document!
Vacuuming
The following SQL code displays the thresholds for when Autovacuum will clean up dead rows.
Dead rows occur in postgres when records are updated or deleted.
SELECT relname, n_live_tup, n_dead_tup, FLOOR(current_setting('autovacuum_vacuum_threshold')::INTEGER + (current_setting('autovacuum_vacuum_scale_factor')::NUMERIC * (n_live_tup))) AS "Autovacuum Threshold", round(n_dead_tup / FLOOR(current_setting('autovacuum_vacuum_threshold')::INTEGER + (current_setting('autovacuum_vacuum_scale_factor')::NUMERIC * (n_live_tup)))*100,2) AS "Percentage", last_vacuum, last_autovacuum FROM pg_stat_user_tables WHERE n_live_tup > 0 ORDER BY 5 DESC LIMIT 10;
postgresqlvacuum.1631996777.txt.gz · Last modified: 2025/03/08 22:23 (external edit)