PostgreSQL列表和订单表的大小 [英] postgresql list and order tables by size

查看:82
本文介绍了PostgreSQL列表和订单表的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以列出PostgreSQL数据库中的所有表并按大小排序?

Is there an easy way to list all tables from PostgreSQL database and order them by size?

伪代码

SELECT * FROM tables
ORDER by tables.size

我正在使用 PostgreSQL 9.3.2

推荐答案

select table_name, pg_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'public'
order by 2

这将显示架构中所有表的大小 public 如果您有多个架构,则可能要使用:

This shows you the size of all tables in the schema public if you have multiple schemas, you might want to use:

select table_schema, table_name, pg_relation_size('"'||table_schema||'"."'||table_name||'"')
from information_schema.tables
order by 3

SQLFiddle示例: http://sqlfiddle.com/#!15/13157/3

SQLFiddle example: http://sqlfiddle.com/#!15/13157/3

所有列表在手册中显示大小函数。

List of all object size functions in the manual.

这篇关于PostgreSQL列表和订单表的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆