Updated on 2024-05-07 GMT+08:00

PG_STATS

PG_STATS displays single-column statistics stored in the pg_statistic table. The GUC parameter autovacuum_naptime specifies the interval for updating statistics recorded in the view.

Table 1 PG_STATS columns

Name

Type

Reference

Description

schemaname

name

nspname in PG_NAMESPACE

Name of the schema that contains a table.

tablename

name

PG_CLASS.relname

Table name.

attname

name

PG_ATTRIBUTE.attname

Field name.

inherited

boolean

-

Inherited tables are not supported currently. The value of this column is false.

null_frac

real

-

Percentage of column entries that are null.

avg_width

integer

-

Average width in bytes of column's entries.

n_distinct

real

-

  • Estimated number of distinct values in the column if the value is greater than 0.
  • Negative number obtained by multiplying the result calculated by dividing the number of distinct values by the number of rows by –1 if the value is less than 0. For example, –1 indicates that the number of distinct values is the same as the number of rows for a column combination.
    1. The negated form is used when ANALYZE believes that the number of distinct values is likely to increase as the table grows.
    2. The positive form is used when the column seems to have a fixed number of possible values.
  • The number of distinct values is unknown if the value is 0.

n_dndistinct

real

-

Number of not-null distinct values in the dn1 column.
  • Exact number of distinct values if the value is greater than 0.
  • Negative number obtained by multiplying the result calculated by dividing the number of distinct values by the number of rows by –1 if the value is less than 0. For example, if the value of a column appears twice in average, set n_dndistinct to -0.5.
  • The number of distinct values is unknown if the value is 0.

most_common_vals

anyarray

-

List of the most common values in a column. If this column does not have the most common value, the value is NULL.

most_common_freqs

real[]

-

List of the frequencies of the most common values in a column. The frequencies are obtained by dividing the number of occurrences of each value by the number of rows. (NULL if most_common_vals is NULL)

histogram_bounds

anyarray

-

Frequency histogram consisting of values excluding null values and MVC values. If a value appears in the value of most_common_vals, it does not appear in the histogram. If the column data type does not have the < operator or the list specified by most_common_vals contains all values of the column, the histogram information of the column is NULL.

correlation

real

-

Correlation between the physical row sequence and logical row sequence of a column value. The value ranges from –1 to +1. When the value is close to –1 or +1, the index scan overhead is less than that when the value is close to 0 because random access to the disk is reduced. 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.

most_common_elem_freqs

real[]

-

List that records the frequency of the most commonly used non-null elements.

elem_count_histogram

real[]

-

A histogram of the counts of distinct non-null element values.