The pg_stat_all_indexes view shows one row for each index in the current database that displays statistics about accesses to that specific index.

The pg_stat_user_indexes and pg_stat_sys_indexes views contain the same information, but filtered to only show user and system indexes respectively.

In Greenplum Database 6, the pg_stat_*_indexes views display access statistics for indexes only from the master instance. Access statistics from segment instances are ignored. You can create views that display usage statistics that combine statistics from the master and the segment instances, see Index Access Statistics from the Master and Segment Instances.

ColumnTypeDescription
relidoidOID of the table for this index
indexrelidoidOID of this index
schemanamenameName of the schema this index is in
relnamenameName of the table for this index
indexrelnamenameName of this index
idx_scanbigintTotal number of index scans initiated on this index from all segment instances
idx_tup_readbigintNumber of index entries returned by scans on this index
idx_tup_fetchbigintNumber of live table rows fetched by simple index scans using this index

Index Access Statistics from the Master and Segment Instances

To display index 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 index access statistics views
  2. -- pg_stat_all_indexes_gpdb6
  3. -- pg_stat_sys_indexes_gpdb6
  4. -- pg_stat_user_indexes_gpdb6
  5. CREATE VIEW pg_stat_all_indexes_gpdb6 AS
  6. SELECT
  7. s.relid,
  8. s.indexrelid,
  9. s.schemaname,
  10. s.relname,
  11. s.indexrelname,
  12. m.idx_scan,
  13. m.idx_tup_read,
  14. m.idx_tup_fetch
  15. FROM
  16. (SELECT
  17. relid,
  18. indexrelid,
  19. schemaname,
  20. relname,
  21. indexrelname,
  22. sum(idx_scan) as idx_scan,
  23. sum(idx_tup_read) as idx_tup_read,
  24. sum(idx_tup_fetch) as idx_tup_fetch
  25. FROM gp_dist_random('pg_stat_all_indexes')
  26. WHERE relid >= 16384
  27. GROUP BY relid, indexrelid, schemaname, relname, indexrelname
  28. UNION ALL
  29. SELECT *
  30. FROM pg_stat_all_indexes
  31. WHERE relid < 16384) m, pg_stat_all_indexes s
  32. WHERE m.relid = s.relid;
  33. CREATE VIEW pg_stat_sys_indexes_gpdb6 AS
  34. SELECT * FROM pg_stat_all_indexes_gpdb6
  35. WHERE schemaname IN ('pg_catalog', 'information_schema') OR
  36. schemaname ~ '^pg_toast';
  37. CREATE VIEW pg_stat_user_indexes_gpdb6 AS
  38. SELECT * FROM pg_stat_all_indexes_gpdb6
  39. WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
  40. schemaname !~ '^pg_toast';

Parent topic: System Catalogs Definitions