Check statistics targets in PostgreSQL

后端 未结 2 1963
独厮守ぢ
独厮守ぢ 2020-12-17 10:30

I have searched but been unable to find any simple, straight forward answer to this. How do I check the current statistics targets used by ANALYZE?

相关标签:
2条回答
  • 2020-12-17 11:09

    This provides a cleaner view of current statistics being collected

    SELECT attrelid::regclass, attname, attstattarget FROM pg_attribute WHERE attstattarget >= 0 order by attstattarget desc;
    
    0 讨论(0)
  • 2020-12-17 11:22

    The setting for the statistics target is stored per column in the catalog table 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 creation script in the object browser of pgAdmin, where it is appended if the value is distinct from the default in default_statistics_target.

    I quote the manual on attstattarget:

    attstattarget controls the level of detail of statistics accumulated for this column by ANALYZE. A zero value indicates that no statistics should be collected. A negative value says to use the system default statistics target. The exact meaning of positive values is data type-dependent. For scalar data types, attstattarget is both the target number of "most common values" to collect, and the target number of histogram bins to create.

    Bold emphasis mine.

    0 讨论(0)
提交回复
热议问题