跳转到主要内容
← 目录图谱 / pg_stats

SYSTEM VIEW · 系统视图

pg_stats

The view pg_stats provides access to the information stored in the pg_statistic catalog. This view allows access only to rows of pg_statistic that correspond to tables the user has permission to read, and therefore it is safe to allow public read access to this view. pg_stats is also designed to present the information in a more readable format than the underlying catalog — at the cost that its schema must be extended whenever new slot types are defined for pg_statistic.

首次收录 PG 9.0最近收录 PG 19当前字段 17

已与 PostgreSQL 18.6 实例逐字段核对 · 原始实测记录 ↗

字段结构 PostgreSQL 18

pg_stats
字段 / COLUMN类型 / TYPE说明 / DESCRIPTION
schemaname name Name of schema containing table引用:pg_namespace.nspname
tablename name Name of table引用:pg_class.relname
attname name Name of column described by this row引用:pg_attribute.attname
inherited boolean文档原写法:bool If true, this row includes values from child tables, not just the values in the specified table
null_frac real文档原写法:float4 Fraction of column entries that are null
avg_width integer文档原写法:int4 Average width in bytes of column's entries
n_distinct real文档原写法:float4 If greater than zero, the estimated number of distinct values in the column. If less than zero, the negative of the number of distinct values divided by the number of rows. (The negated form is used when ANALYZE believes that the number of distinct values is likely to increase as the table grows; the positive form is used when the column seems to have a fixed number of possible values.) For example, -1 indicates a unique column in which the number of distinct values is the same as the number of rows.
most_common_vals anyarray A list of the most common values in the column. (Null if no values seem to be more common than any others.)
most_common_freqs real[]文档原写法:float4[] A list of the frequencies of the most common values, i.e., number of occurrences of each divided by total number of rows. (Null when most_common_vals is.)
histogram_bounds anyarray A list of values that divide the column's values into groups of approximately equal population. The values in most_common_vals, if present, are omitted from this histogram calculation. (This column is null if the column data type does not have a < operator or if the most_common_vals list accounts for the entire population.)
correlation real文档原写法:float4 Statistical correlation between physical row ordering and logical ordering of the column values. This ranges from -1 to +1. When the value is near -1 or +1, an index scan on the column will be estimated to be cheaper than when it is near zero, due to reduction of random access to the disk. (This column is null if the column data type does not have a < operator.)
most_common_elems anyarray A list of non-null element values most often appearing within values of the column. (Null for scalar types.)
most_common_elem_freqs real[]文档原写法:float4[] A list of the frequencies of the most common element values, i.e., the fraction of rows containing at least one instance of the given value. Two or three additional values follow the per-element frequencies; these are the minimum and maximum of the preceding per-element frequencies, and optionally the frequency of null elements. (Null when most_common_elems is.)
elem_count_histogram real[]文档原写法:float4[] A histogram of the counts of distinct non-null element values within the values of the column, followed by the average number of distinct non-null elements. (Null for scalar types.)
range_length_histogram anyarray A histogram of the lengths of non-empty and non-null range values of a range type column. (Null for non-range types.) This histogram is calculated using the subtype_diff range function regardless of whether range bounds are inclusive.
range_empty_frac real文档原写法:float4 Fraction of column entries whose values are empty ranges. (Null for non-range types.)
range_bounds_histogram anyarray A histogram of lower and upper bounds of non-empty and non-null range values. (Null for non-range types.) These two histograms are represented as a single array of ranges, whose lower bounds represent the histogram of lower bounds, and upper bounds represent the histogram of upper bounds.

标记“隐式列”的字段不包含在 SELECT * 中;部分早期统计视图由同版本源码补全,额外来源会显示在字段说明中。

字段演化矩阵

悬停查看字段类型
存在新增 / 类型或属性变化移除
字段 / COLUMN9.09.19.29.39.49.59.610111213141516171819
schemaname
tablename
attname
inherited
null_frac
avg_width
n_distinct
most_common_vals
most_common_freqs
histogram_bounds
correlation
most_common_elems
most_common_elem_freqs
elem_count_histogram
range_length_histogram
range_empty_frac
range_bounds_histogram
tableid
attnum

9.0 是收录基线;基线中已存在的字段不标记为新增。矩阵按字段名称对齐,重命名显示为旧字段移除与新字段新增。

演化时间线

相邻大版本的变化

PostgreSQL 19 ← 18

+ tableid+ attnum

PostgreSQL 17 ← 16

+ range_length_histogram+ range_empty_frac+ range_bounds_histogram

PostgreSQL 15 ← 14

1 处字段说明更新

PostgreSQL 14 ← 13

1 处字段说明更新

PostgreSQL 9.2 ← 9.1

+ most_common_elems+ most_common_elem_freqs+ elem_count_histogram2 处字段说明更新

比较任意两个版本

选择两个版本,查看字段的新增、移除与类型变化。交互比较需要 JavaScript;演化时间线可直接阅读。