3种数据库查询数据文件大小

一、MySQL

select table_name, #表名
       sum(data_length+index_length)/(1024)/(1024) as total_mb,  #总大小MB 
       sum(data_length)/(1024)/(1024) as data_mb,   #数据文件大小MB 
       sum(index_length)/(1024)/(1024) as index_mb  #索引大小MB
from information_schema.tables 
where table_schema='ABC' group by table_name    #ABC为数据库名称

二、SqlServer

select name,   #数据文件名称
       convert(float,size) * (8192.0/1024.0)/1024.0   #转为MB
from bserp3.dbo.sysfiles

三、Oracle

SELECT a.tablespace_name "表空间名",
total "表空间大小",
free "表空间剩余大小",
(total - free) "表空间使用大小",
total / (1024 * 1024 * 1024) "表空间大小(G)",
free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total
FROM dba_data_files
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
#查看每张表所占大小
SELECT segment_name AS TABLENAME,
       BYTES B,
       BYTES/1024 KB,
       BYTES/1024/1024 MB 
FROM user_segments 
WHERE segment_name='ABC'  #ABC为表名

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章