分析rds的空间占用
文章目录
- 场景
- 查询各个schema占用的空间大小
- 查询指定schema的空间分布情况
场景
数据库实例可用空间告警, 我们的数据库实例硬盘空间是500GB的, 所以得分析下各个schema的占用
查询各个schema占用的空间大小
SELECT table_schema AS '数据库名称',ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS '总大小(GB)',ROUND(SUM(data_length) / 1024 / 1024 / 1024, 2) AS '数据大小(GB)',ROUND(SUM(index_length) / 1024 / 1024 / 1024, 2) AS '索引大小(GB)',COUNT(*) AS '表数量'
FROM information_schema.TABLES
GROUP BY table_schema
ORDER BY SUM(data_length + index_length) DESC;
查询指定schema的空间分布情况
where table_schema 指定数据库
SELECT table_name AS '表名',round(data_length/1024/1024/1024, 2) AS '数据大小(GB)',round(index_length/1024/1024/1024, 2) AS '索引大小(GB)',round((data_length + index_length)/1024/1024/1024, 2) AS '总大小(GB)',table_rows AS '行数'
FROM information_schema.TABLES
WHERE table_schema = 'ad'
ORDER BY (data_length + index_length) DESC;