Skip to content

Instantly share code, notes, and snippets.

@overplumbum
Last active December 6, 2022 12:46
Show Gist options
  • Save overplumbum/1237114 to your computer and use it in GitHub Desktop.
Save overplumbum/1237114 to your computer and use it in GitHub Desktop.
PostgreSQL tables sizes with related TOAST tables
SELECT E'{| border=1 cellspacing=0 cellpadding=5\n|+\n|тип || relation || size || чей toast || mantainer || планы\n|-\n' || array_to_string(ARRAY(
SELECT '|' || C.relkind ||
'||' || nspname || '.' || C.relname ||
'||' || pg_size_pretty(pg_relation_size(C.oid)) ||
'||' || COALESCE(T.relname, '-') ||
'||' || '/author/' ||
'||' || '/wtf?/' || E'\n|-'
/*SELECT C.relkind, nspname || '.' || C.relname AS "relation",
pg_size_pretty(pg_relation_size(C.oid)) AS "size",
T.relname AS "toastrel"
*/
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
LEFT JOIN pg_class T ON (T.reltoastrelid=C.oid)
WHERE
nspname NOT IN ('pg_catalog', 'information_schema')
AND pg_relation_size(C.oid) > 11000000
ORDER BY pg_relation_size(C.oid) DESC
LIMIT 200
), E'\n') || E'\n|}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment