比尔萄堡

上帝说: “要有光” 于是,就有了光。


  • 首页

  • 归档

  • 关于我

  • 公益404

  • 搜索

数据库查看表大小

时间: 2021-11-10 分类: 问题排查/数据库   字数: 183 字 阅读: 1分钟 阅读次数:

MySQL

查看单个表 大小

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE
    TABLE_SCHEMA = "$DB_NAME"
  AND
    TABLE_NAME = "$TABLE_NAME"
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;

查看前十大的表, size单位是MB

select table_schema as database_name, table_name, round( (data_length + index_length) / 1024 / 1024, 2) as total_size, round( (data_length) / 1024 / 1024, 2) as data_size, round( (index_length) / 1024 / 1024, 2) as index_size from information_schema.tables where table_schema not in ('information_schema', 'mysql', 'performance_schema' ,'sys') and table_type = 'BASE TABLE' order by total_size desc limit 10;

Postgres

// 查看表数据占用空间
SELECT pg_size_pretty(pg_relation_size('sms_push_log'));
// 查看表索引占用空间
SELECT pg_size_pretty(pg_indexes_size('sms_push_log'));
// 查看表的总占用空间
SELECT pg_size_pretty(pg_total_relation_size('sms_push_log'));
查看当前数据库 索引利用率
SELECT 
  relname, 
  100 * idx_scan / (seq_scan + idx_scan) percent_of_times_index_used, 
  n_live_tup rows_in_table
FROM 
  pg_stat_user_tables
WHERE 
    seq_scan + idx_scan > 0 
ORDER BY 
  n_live_tup DESC;
#数据库# #调优#

标题:数据库查看表大小

作者:训导主任林作栋

声明: 本博客文章除特别声明外,均采用 CC BY-NC-SA 3.0许可协议,转载请注明出处!

创作实属不易,如有帮助,那就打赏博主些许茶钱吧 ^_^
WeChat Pay

微信打赏

Alipay

支付宝打赏

migration with k8s
记一次大文件上传失败
训导主任林作栋

训导主任林作栋

戏谑的码农,北野武的拥趸,李安的迷弟,伍佰的Fans

55 日志
23 分类
62 标签
豆瓣
友情链接
  • Obsidian
  • V2EX
  • 关注黑客与极客
  • 廖雪峰
标签云
  • Linux 6
  • K8s 5
  • 数据库 5
  • Golang 4
  • Etcd 3
  • Mysql 3
  • Ai 2
  • Gitlab 2
  • Postgres 2
  • 前端 2
© 2010 - 2024 比尔萄堡
Powered by - Hugo v0.58.2 / Theme by - NexT
/
Storage by Vercel / 刘 ICP 备 18047355 号
0%