How to: list table sizes in PostgreSQL Database using only SQL and built in PG functions.
The below SQL will output details of every table in the current DB you are connected to including all schemas you have access to. The code is easily modifiable to include only a specific table of schema by adding filters to the inner most where statement i.e.
where relkind = 'r'.
nspname to filter on schemas and
relname to filter on tables.
Below is the full code
pg_namespace tables we join them together to get the table details. In the next level up with calculate the table size in bytes and finally we tidy up the bytes using the built-in function
pg_size_pretty to make it more readable.
- PostgreSQL link