PostgreSQL – Vacuum and Analyze Stats for Tables

This query retrieves information about the health of PostgreSQL tables

SELECT
    schemaname,
    relname AS table_name,
    last_vacuum,
    last_autovacuum,
    last_analyze,
    last_autoanalyze,
    n_live_tup AS live_tuples,
    n_dead_tup AS dead_tuples,
    vacuum_count,
    autovacuum_count
FROM 
    pg_stat_all_tables
WHERE 
    schemaname NOT IN ('pg_catalog', 'information_schema')
    and n_dead_tup  > 0
ORDER BY 
    n_dead_tup DESC;    

Voila:

Leave a Reply

Your email address will not be published. Required fields are marked *