Table statistics
Basic statistics about each table in your database are available in the view pg_stat_all_tables
. Since you probably don't want that cluttered by the many system catalog tables, the data in there is split into two additional views: pg_stat_sys_tables
, which only shows the system tables and pg_stat_user_tables
, which as you might expect only shows your tables. In most cases pg_stat_user_tables
is the one you'll want to look at.
The first useful thing you can use this data for is monitoring how well vacuum is working on your database. You get estimated live and dead tuple counts and timestamps for when vacuum and autovacuum last processed the table (these are not all available before version 8.3). Information about how to monitor that data is covered in Chapter 7, Routine Maintenance.
You can use this view to determine whether tables are being accessed by sequential or index scans:
pgbench=# SELECT schemaname,relname,seq_scan,idx_scan,cast(idx_scan AS numeric...