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

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

你可能感兴趣的:(统计数据库各表占用空间大小)