Viewing and estimating with statistics

The statistics information collected for each table is easiest to see using the pg_stats view. The amount of information it returns is a bit overwhelming though, and not well suited to the standard display format. The following script is named table-stats.sh in the book's file set, and it tries to display the statistics information for a particular table (with an optional database too) in a way that makes the information as readable as possible:

#!/bin/bashif [ -z "$1" ]; then  echo "Usage: table-stats.sh table [db]"  exit 1fiTABLENAME="$1"if [ -n "$2" ] ; then  DB="-d $2"fiPSQL="psql $DB -x -c "$PSQL "SELECT  tablename,attname,null_frac,avg_width,n_distinct,correlation, most_common_vals,most_common_freqs,histogram_bounds ...

Get PostgreSQL 9.6 High Performance now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.