Custom Alert - Last Analyze


ANALYZE gathers statistics for the query planner to create the most efficient query execution paths. Per PostgreSQL documentation, accurate statistics will help the planner to choose the most appropriate query plan, and thereby improve the speed of query processing. 

This alert utilizes pg_stat_user_tables to let you know how old a given relation(s) statistics are.  

Alert Definition

To create the alert, click on Alerts > Manage Alerts tab and create a Custom Alert of type Custom SQL Alert - Multiple Numeric Return. Configure the alert with values similar to these:

Alert Name: Last Analyze

Execution Interval: 8 hours -- You may want to change the interval based on your database workload.  

Notification Text: Empty

SQL Statement:

select schemaname ||'.'||relname, extract(hour FROM now()-last_analyze) from pg_stat_user_tables
where last_analyze is not null;

Execute Against: Monitored Instance

Units: Hours

High Threshold: Min 360, Max <blank> 

Medium Threshold: Min 192, Max 360

Low Threshold: Min 168, Max 192