mysql、postgresql 数据库数据量查询
一、🌞前言
本文讲解如何获取mysql、postgresql数据库当前数据量的大小,可作为是否分库的指标之一。希望能帮助到您。
二、🌞数据量查询
1、🌙mysql 数据库数据量查询
SELECT SUM(table_rows) FROM TABLES WHERE TABLE_SCHEMA = '库表名称' ORDER BY table_rows DESC;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='库表名称';
SELECT
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;
效果如下
2、🌙postgresql 数据库数据量查询
select pg_size_pretty(pg_database_size('数据库名称')) as size;
效果如下图:
摘抄自网络,便于检索查找。

浙公网安备 33010602011771号