Last active
January 9, 2021 11:01
-
-
Save cquest/8331683 to your computer and use it in GitHub Desktop.
postgresql: liste des table/index par taille + infos sur le tablespace utilisé (https://coderwall.com/p/eghbjq)
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 N.nspname || '.' || C.relname AS "relation", | |
CASE WHEN reltype = 0 | |
THEN pg_size_pretty(pg_total_relation_size(C.oid)) || ' (index)' | |
ELSE pg_size_pretty(pg_total_relation_size(C.oid)) || ' (' || pg_size_pretty(pg_relation_size(C.oid)) || ' data)' | |
END AS "size (data)", | |
COALESCE(T.tablespace, I.tablespace, '') AS "tablespace" | |
FROM pg_class C | |
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
LEFT JOIN pg_tables T ON (T.tablename = C.relname) | |
LEFT JOIN pg_indexes I ON (I.indexname = C.relname) | |
LEFT JOIN pg_tablespace TS ON TS.spcname = T.tablespace | |
LEFT JOIN pg_tablespace XS ON XS.spcname = I.tablespace | |
WHERE nspname NOT IN ('pg_catalog','pg_toast','information_schema') | |
ORDER BY pg_total_relation_size(C.oid) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment