Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created August 24, 2010 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregglind/548041 to your computer and use it in GitHub Desktop.
Save gregglind/548041 to your computer and use it in GitHub Desktop.
/****************************
* Unexpected result:
* analyzing this empty table doesn't update last_analzye in pg_stat_all_tables
*****************************/
drop table if exists a;
create table a (exists int);
analyze a;
select relname,last_analyze from pg_stat_all_tables where relname = 'a';
Copy link

ghost commented Aug 24, 2010

$ select relname,last_analyze from pg_stat_all_tables where relname = 'a';
relname | last_analyze
---------+-------------------------------
a | 2010-08-24 20:28:21.477849+02
(1 row)

@JonNelson
Copy link

You want last_autoanalyze for the last time the autovacuum daemon analyzed the table. It is odd that the 'analyze' value isn't updated when you do a manual ANALYZE (on a new, empty table) but a quick look at the code suggests that nothing is wrong, either. Consider filing a bug. Additionally, it only appears to happen in this one instance - namely, once the table has data in it, even if that data is later removed, 'ANALYZE' goes through all the motions - this I find odd, but not necessarily troubling.

See the autovacuum daemon settings for the various thresholds under which a table is automatically vacuumed and/or analyzed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment