Skip to content

Instantly share code, notes, and snippets.

@romank0
Created December 1, 2017 16:15
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 romank0/74f9d1d807bd3f41c0729d0fc6126749 to your computer and use it in GitHub Desktop.
Save romank0/74f9d1d807bd3f41c0729d0fc6126749 to your computer and use it in GitHub Desktop.
get table size
SELECT
nspname as schemaname,
c.relname::text,
pg_size_pretty(pg_relation_size(c.oid)) as "size",
pg_size_pretty
(
case when c.reltoastrelid > 0
then
pg_relation_size(c.reltoastrelid)
else 0 end
+
case when t.reltoastidxid > 0
then
pg_relation_size(t.reltoastidxid)
else 0 end
) as toast,
pg_size_pretty(cast((
SELECT
coalesce(sum(pg_relation_size(i.indexrelid)), 0)
FROM
pg_index i
WHERE
i.indrelid = c.oid
)
as int8)) as associated_idx_size,
pg_size_pretty(pg_total_relation_size(c.oid)) as "total"
FROM
pg_class c
LEFT JOIN
pg_namespace n ON (n.oid = c.relnamespace)
LEFT JOIN
pg_class t on (c.reltoastrelid=t.oid)
WHERE
c.relname = 'document_head';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment