pg_stat_all_tables

The pg_stat_all_tables view shows one row for each table in the current database (including TOAST tables) to display statistics about accesses to that specific table.

The pg_stat_user_tables and pg_stat_sys_tables views contain the same information, but filtered to only show user and system tables respectively.

In Greenplum Database 5, the pg_stat_*_tables views display access statistics for tables only from the master instance. Access statistics from segment instances are ignored. You can create views that display access statistics that combine statistics from the master and the segment instances, see Table Access Statistics from the Master and Segment Instances.

ColumnTypeDescription
relidoidOID of a table
schemanamenameName of the schema that this table is in
relnamenameName of this table
seq_scanbigintTotal number of sequential scans initiated on this table from all segment instances
seq_tup_readbigintNumber of live rows fetched by sequential scans
idx_scanbigintTotal number of index scans initiated on this table from all segment instances
idx_tup_fetchbigintNumber of live rows fetched by index scans
n_tup_insbigintNumber of rows inserted
n_tup_updbigintNumber of rows updated (includes HOT updated rows)
n_tup_delbigintNumber of rows deleted
n_tup_hot_updbigintNumber of rows HOT updated (i.e., with no separate index update required)
n_live_tupbigintEstimated number of live rows
n_dead_tupbigintEstimated number of dead rows
last_vacuumtimestamp with time zoneLast time this table was manually vacuumed (not counting VACUUM FULL)
last_autovacuumtimestamp with time zoneLast time this table was vacuumed by the autovacuum daemon1. Note: Greenplum Database 5.x does not populate this column value.
last_analyzetimestamp with time zoneLast time this table was manually analyzed
last_autoanalyzetimestamp with time zoneLast time this table was analyzed by the autovacuum daemon1. Note: Greenplum Database 5.x does not populate this column value.

Note: 1In Greenplum Database, the autovacuum daemon is deactivated and not supported for user defined databases.

Table Access Statistics from the Master and Segment Instances

To display table access statistics that combine statistics from the master and the segment instances, you can create these views. A user requires SELECT privilege on the views to use them.

  1. -- Create these table access statistics views
  2. -- pg_stat_all_tables_gpdb5
  3. -- pg_stat_sys_tables_gpdb5
  4. -- pg_stat_user_tables_gpdb5
  5. CREATE VIEW pg_stat_all_tables_gpdb5 AS
  6. SELECT
  7. s.relid,
  8. s.schemaname,
  9. s.relname,
  10. m.seq_scan,
  11. m.seq_tup_read,
  12. m.idx_scan,
  13. m.idx_tup_fetch,
  14. m.n_tup_ins,
  15. m.n_tup_upd,
  16. m.n_tup_del,
  17. m.n_tup_hot_upd,
  18. m.n_live_tup,
  19. m.n_dead_tup,
  20. s.last_vacuum,
  21. s.last_analyze
  22. FROM
  23. (SELECT
  24. relid,
  25. schemaname,
  26. relname,
  27. sum(seq_scan) as seq_scan,
  28. sum(seq_tup_read) as seq_tup_read,
  29. sum(idx_scan) as idx_scan,
  30. sum(idx_tup_fetch) as idx_tup_fetch,
  31. sum(n_tup_ins) as n_tup_ins,
  32. sum(n_tup_upd) as n_tup_upd,
  33. sum(n_tup_del) as n_tup_del,
  34. sum(n_tup_hot_upd) as n_tup_hot_upd,
  35. sum(n_live_tup) as n_live_tup,
  36. sum(n_dead_tup) as n_dead_tup,
  37. max(last_vacuum) as last_vacuum,
  38. max(last_analyze) as last_analyze
  39. FROM gp_dist_random('pg_stat_all_tables')
  40. WHERE relid >= 16384
  41. GROUP BY relid, schemaname, relname
  42. UNION ALL
  43. SELECT *
  44. FROM pg_stat_all_tables
  45. WHERE relid < 16384) m, pg_stat_all_tables s
  46. WHERE m.relid = s.relid;
  47. CREATE VIEW pg_stat_sys_tables_gpdb5 AS
  48. SELECT * FROM pg_stat_all_tables_new
  49. WHERE schemaname IN ('pg_catalog', 'information_schema') OR
  50. schemaname ~ '^pg_toast';
  51. CREATE VIEW pg_stat_user_tables_gpdb5 AS
  52. SELECT * FROM pg_stat_all_tables_gpdb5
  53. WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
  54. schemaname !~ '^pg_toast';

Parent topic: System Catalogs Definitions