postgresql list and order tables by size

前端 未结 9 1200
不思量自难忘°
不思量自难忘° 2020-12-12 11:16

How can I list all the tables of a PostgreSQL database and order them by size?

9条回答
  •  伪装坚强ぢ
    2020-12-12 11:51

    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.

提交回复
热议问题