Created
March 17, 2022 07:03
-
-
Save ashkangoleh/18480b4e7345bf04ed96b81c221e99cd to your computer and use it in GitHub Desktop.
Postgresql table sized depends on schema
This file contains 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
For get all of tables size depends on schema there is complex query that show tables splited size (tables , indexes) | |
SELECT | |
schema_name, | |
relname, | |
pg_size_pretty(table_size) AS size, | |
table_size | |
FROM ( | |
SELECT | |
pg_catalog.pg_namespace.nspname AS schema_name, | |
relname, | |
pg_relation_size(pg_catalog.pg_class.oid) AS table_size | |
FROM pg_catalog.pg_class | |
JOIN pg_catalog.pg_namespace ON relnamespace = pg_catalog.pg_namespace.oid | |
) t | |
WHERE schema_name NOT LIKE 'pg_%' AND schema_name='public' | |
ORDER BY table_size DESC; | |
for example: | |
+---------------+--------------------+--------+--------------+ | |
| schema_name | relname | size | table_size | | |
|---------------+--------------------+--------+--------------| | |
| public | ....... | 274 GB | 294691528704 | | |
| public | ....... .......... | 162 GB | 174062936064 | | |
| public | ........... | 95 GB | 101768716288 | | |
+---------------+--------------------+--------+--------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment