pg_statistic
The pg_statistic system catalog table stores statistical data about the contents of the database.
Entries are created by ANALYZE and subsequently used by the query optimizer.
There is one entry for each table column that has been analyzed.
Note that all the statistical data is inherently approximate, even assuming that it is up to date.
pg_statistic also stores statistical data about the values of index expressions.
These are described as if they were actual data columns; in particular, starelid references the index.
However, no entry is made for an ordinary non-expression index column, since it would be redundant with the entry for the underlying table column.
Currently, entries for index expressions always have stainherit = false.
When stainherit = false, there is normally one entry for each table column that has been analyzed.
If the table has inheritance children, Greengage DB creates a second entry with stainherit = true.
This row represents the column’s statistics over the inheritance tree, for example, statistics for the data you would see with SELECT column FROM table*, whereas the stainherit = false row represents the results of SELECT column FROM ONLY table.
Since different kinds of statistics may be appropriate for different kinds of data, pg_statistic is designed not to assume very much about what sort of statistics it stores.
Only extremely general statistics (such as nullness) are given dedicated columns in pg_statistic.
Everything else is stored in slots, which are groups of associated columns whose content is identified by a code number in one of the slot’s columns.
Statistical information about a table’s contents should be considered sensitive (for example, minimum and maximum values of a salary column).
pg_stats is a publicly readable view on pg_statistic that only exposes information about those tables that are readable by the current user.
Diagnostic tools such as gpsd and minirepro collect sensitive information from pg_statistic, such as histogram boundaries, in a clear, readable form.
Always review the output files of these utilities to ensure that the contents are acceptable for transport outside of the database in your organization.
| Column | Type | References | Description |
|---|---|---|---|
starelid |
oid |
pg_class.oid |
The table or index that the described column belongs to |
staattnum |
int2 |
pg_attribute.attnum |
The number of the described column |
stainherit |
boolean |
— |
If |
stanullfrac |
float4 |
— |
The fraction of the column’s entries that are |
stawidth |
integer |
— |
The average stored width, in bytes, of non- |
stadistinct |
float4 |
— |
The number of distinct non- |
stakind*N* |
int2 |
— |
A code number indicating the kind of statistics stored in the N-th slot of the |
staop*N* |
oid |
pg_operator.oid |
An operator used to derive the statistics stored in the N-th slot.
For example, a histogram slot would show the |
stanumbers*N* |
float4[] |
— |
Numerical statistics of the appropriate kind for the N-th slot, or |
stavalues*N* |
anyarray |
— |
Column data values of the appropriate kind for the N-th slot, or |