Checking statistics goals in PostgreSQL

I searched, but could not find a simple, direct answer to this question. How to check current statistics targets used by ANALYZE?

+16
sql postgresql database-design
Feb 22 '13 at 22:59
source share
2 answers

The setting for the statistics target is saved for each column in the pg_attribute catalog pg_attribute . You can set it like this:

 ALTER TABLE myschama.mytable ALTER mycolumn SET STATISTICS 127; 

And check it like this:

 SELECT attstattarget FROM pg_attribute WHERE attrelid = 'myschama.mytable'::regclass AND attname = 'mycolumn'; 

Or you just look at the script for creating pgAdmin objects in the browser, where it is added if the value is different from the default in default_statistics_target .

I am quoting the attstattarget :

attstattarget controls the granularity of statistics collected for this ANALYZE column. A value of zero indicates that statistics should not be collected. A negative value indicates the use of a default system statistics target. The exact value of positive values โ€‹โ€‹depends on the data type. For scalar data types, attstattarget is both the target number of the โ€œmost common values" to collect and the target number of histogram bins to create.

Bold accent mine.

+23
Feb 22 '13 at 23:22
source share

This provides a cleaner view of the current statistics collected.

 SELECT attrelid::regclass, attname, attstattarget FROM pg_attribute WHERE attstattarget >= 0 order by attstattarget desc; 
+1
Mar 10 '17 at 11:14
source share



All Articles