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/bash if [ -z "$1" ]; then echo "Usage: table-stats.sh table [db]" exit 1 fi TABLENAME="$1" if [ -n "$2" ] ; then DB="-d $2" fi PSQL="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 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.