Created
February 27, 2017 23:05
-
-
Save ShawnMTherrien/e1ee2f95d0b239688e1babe2726b3a5a to your computer and use it in GitHub Desktop.
PGSQL - DBA - Table Analyzed Status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH cte_analyze_status as ( | |
SELECT | |
relname as table_name | |
,last_vacuum | |
,last_autovacuum | |
,last_analyze | |
,last_autoanalyze | |
,n_dead_tup | |
,n_live_tup | |
,CASE WHEN n_dead_tup > 0 THEN n_dead_tup::float / n_live_tup::float ELSE 0.0 END as dead_decimal | |
FROM pg_stat_user_tables ) | |
SELECT | |
table_name | |
,last_vacuum | |
,last_autovacuum | |
,last_analyze | |
,last_autoanalyze | |
,n_dead_tup | |
,n_live_tup | |
,dead_decimal | |
,round(((a.dead_decimal)*100.0)::numeric, 2) as dead_percent | |
FROM cte_analyze_status a | |
WHERE table_name like 'etl_%' or table_name like 'base_%' | |
ORDER BY a.table_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment