Quantcast
Channel: Planet PostgreSQL
Viewing all articles
Browse latest Browse all 9645

Amit Langote: PostgreSQL Statistics: pg_statistic and pg_stat(io)_*

$
0
0

We hear about two kinds of statistics in PostgreSQL:

  1. PostgreSQL planner statistics (pg_statistic catalog/pg_stats view), and
  2. PostgreSQL server activity statistics (pg_stat(io)_* views)

It is important to understand that #1 pertains to the statistical data about the contents of the database, whereas #2, the statistics of server activity viz. the accesses to tables, indexes, disk-block accesses that they incur and such. 

So, what are the differences between how these statistics are used? Well, #1 is used by the planner as different kinds of estimates about the data contained in various tables, indexes in the cluster (that is the data directory managed by this server instance). This may include various things like distribution of data in various columns in tables viz. fraction of NULLs, average row width, number of distinct values, and so on. This link sheds some light on the matter. Planner, this data (about data) at its disposal can make smart decisions about choosing plans for a given query. These statistics are mainly updated by ANALYZE.

#2, on the other hand, are the operational data about server activity. A DBA or a system administrator may be interested in such data for reporting purposes. There are various tools (likepg_statsinfo) which utilize various pg_stat_* views exported by the server to create activity reports. I won’t go into details of all the statistics here for the sake of brevity. There is an auxiliary PostgreSQL process called stats collector process, that transmits collected information to backends through temporary files located under pg_stat_tmp directory in the server data directory. They are also copied permanently to pg_stat at the server shutdown to be  used after server is restarted.



Viewing all articles
Browse latest Browse all 9645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>