Check statistics targets in PostgreSQL

我是研究僧i 提交于 2019-11-29 05:40:10

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.

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!