How can I list all the tables of a PostgreSQL database and order them by size?
I like following statement:
SELECT
table_name,
pg_size_pretty( pg_total_relation_size(quote_ident(table_name))),
pg_total_relation_size(quote_ident(table_name))
FROM
information_schema.tables
WHERE
table_schema = 'public'
ORDER BY
pg_total_relation_size(quote_ident(table_name)) DESC
You can see total size in a pretty format, but it id ordered correctly too.