对于pg_stas,说明文档在这里:
http://www.postgresql.org/docs/9.1/static/view-pg-stats.html
下面做一个实验:
先建立一个表
postgres=# create table test(id integer); CREATE TABLE postgres=# \x Expanded display is on. postgres=#
此后,观察 pg_stats 中与test表相关的数据,结果是还没有数据。
postgres=# \d pg_stats; View "pg_catalog.pg_stats" Column | Type | Modifiers -------------------+----------+----------- schemaname | name | tablename | attname | inherited | boolean | null_frac | real | avg_width integer | n_distinct | most_common_vals | anyarray | most_common_freqs real[] | histogram_bounds | correlation | postgresselect * from pg_stats where tablename='test'; (No rows)
然后,插入两条数据后看看有何变化:
insert into test values(1);
INSERT 0 1
postgres';
(No rows)
postgres2);
非得anaylize 一下,才可以:
=# analyze;
ANALYZE
postgres';
-[ RECORD 1 ]---+-------
schemaname public
tablename | test
attname | id
inherited | f
null_frac | 0
avg_width 4
n_distinct -1
most_common_vals |
most_common_freqs |
histogram_bounds | {1,2}
correlation 1