Created
December 1, 2017 16:15
-
-
Save romank0/74f9d1d807bd3f41c0729d0fc6126749 to your computer and use it in GitHub Desktop.
get table size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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