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 (or tuples) 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;
autovacuum_analyze_scale_factor | Number of DML prior to analyze as a fraction of reltuples. autovacuum_analyze_threshold | Minimum number of DML prior to analyze. autovacuum_vacuum_scale_factor | Number of DML prior to vacuum as a fraction of reltuples. autovacuum_vacuum_threshold | Minimum number of tuple DML prior to vacuum.
postgresqlvacuum.1631998019.txt.gz · Last modified: 2025/03/08 22:23 (external edit)