Skip to content

Instantly share code, notes, and snippets.

@michelmilezzi
Last active June 26, 2017 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelmilezzi/b52854c920c17b220ba328c7a98cb9e5 to your computer and use it in GitHub Desktop.
Save michelmilezzi/b52854c920c17b220ba328c7a98cb9e5 to your computer and use it in GitHub Desktop.
PostgreSQL query that calculates overall status of indexes
SELECT
COUNT(*) FILTER (WHERE idx_scan = 0) AS no_hit,
COUNT(*) FILTER (WHERE idx_scan > 0) AS used,
COUNT(*) AS total
FROM
pg_stat_user_indexes s
JOIN pg_index i ON (i.indexrelid = s.indexrelid)
WHERE
NOT i.indisprimary;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment