Skip to content

Instantly share code, notes, and snippets.

@ludndev
Last active December 8, 2025 09:46
Show Gist options
  • Select an option

  • Save ludndev/8ec4c959e970d7ed9bde00b0187b980e to your computer and use it in GitHub Desktop.

Select an option

Save ludndev/8ec4c959e970d7ed9bde00b0187b980e to your computer and use it in GitHub Desktop.
check-index-on-postgres

Reindex a specific database

REINDEX DATABASE "databse_name";
SELECT
psui.schemaname,
pc.relname AS index_name,
pg_size_pretty(pg_relation_size(psui.indexrelid)) AS index_size,
psui.idx_scan,
psui.idx_tup_read,
psui.idx_tup_fetch
FROM pg_stat_user_indexes psui
JOIN pg_class pc ON pc.oid = psui.indexrelid
ORDER BY pg_relation_size(psui.indexrelid) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment