Skip to content

Instantly share code, notes, and snippets.

@camallen
Created July 5, 2018 09:14
Show Gist options
  • Save camallen/83d7ce282e06f0388e20d60021d3b802 to your computer and use it in GitHub Desktop.
Save camallen/83d7ce282e06f0388e20d60021d3b802 to your computer and use it in GitHub Desktop.
PG Table & Index size queries
SELECT
nspname AS schema_name,
relname AS index_name,
round(100 * pg_relation_size(indexrelid) / pg_relation_size(indrelid)) / 100 AS index_ratio,
pg_size_pretty(pg_relation_size(indexrelid)) AS index_size,
pg_size_pretty(pg_relation_size(indrelid)) AS table_size
FROM
pg_index I
LEFT JOIN
pg_class C
ON
(C.oid = I.indexrelid)
LEFT JOIN
pg_namespace N
ON
(N.oid = C.relnamespace)
WHERE
C.relkind = 'i' AND
pg_relation_size(indrelid) > 0 AND
relname='idx_temperature_log_log_timestamp'
ORDER BY
pg_relation_size(indexrelid) DESC, index_ratio DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment