美文网首页
统计数据库各表占用空间大小

统计数据库各表占用空间大小

作者: 夜藍 | 来源:发表于2022-11-03 10:45 被阅读0次

MySql

select

table_schema as '数据库',

table_name as '表名',

table_rows as '记录数',

truncate(data_length/1024/1024, 2) as '数据容量(MB)',

truncate(index_length/1024/1024, 2) as '索引容量(MB)'

from information_schema.tables

where table_schema='data_数据库名'

order by data_length desc, table_rows desc;

PgSql

select * from (

SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')AS size

FROM information_schema.tables

) t where table_full_name like '模式名.%'

ORDER by table_full_name DESC

相关文章

网友评论

      本文标题:统计数据库各表占用空间大小

      本文链接:https://www.haomeiwen.com/subject/svzstdtx.html