denrepo

PostgreSQLMaintenance

Dead tuples and last vacuum

Tables with the most dead rows and when they were last vacuumed and analyzed. A high dead_pct with an old last_autovacuum needs attention.

Not yet verified. How scripts are tested

b-pg-vacuum.sql
1SELECT schemaname, relname,2       n_live_tup, n_dead_tup,3       round(100.0 * n_dead_tup / NULLIF(n_live_tup + n_dead_tup, 0), 1) AS dead_pct,4       last_vacuum, last_autovacuum, last_autoanalyze5FROM pg_stat_user_tables6WHERE n_dead_tup > 10007ORDER BY n_dead_tup DESC8LIMIT 20;

Paste it into your query tool.

Open in denrepo