为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM7
【操作系统】:Linux
【CPU】:2
【问题描述】*:如何查询达梦数据库的表空间使用率,阅读很多SQL查询,压根没有考虑数据文件的自动扩展的可能性,有没有成熟靠谱的SQL脚本,查询达梦的数据库表空间使用率的SQL啊!
自己尝试写了个SQL,回复的大哥SQL执行效果看起来不是很理想
SELECT
a.tablespace_name ,
round(b.max_total/(102410241024),2) Max_Total_G,
round(total/ (1024 * 10241024),2) System_Allocated_Total_G,
round(free/ (1024 * 10241024),2) System_Allocated_Free_G,
round((total- free)/(1024 * 1024*1024),2) System_Allocated_Used_G ,
round((total - free) / total, 4) * 100 “System_Allocated_Used_%”,
round(((total- free)/max_total),6)*100 “Max_Used_%”
FROM
(
SELECT
tablespace_name,
SUM(bytes) free
FROM
dba_free_space
GROUP BY
tablespace_name
)
a,
(
SELECT
tablespace_name,
SUM(bytes) total,
sum(decode(AUTOEXTENSIBLE,‘NO’,bytes,MAXBYTES)) max_total
FROM
dba_data_files
GROUP BY
tablespace_name
)
b
WHERE
a.tablespace_name = b.tablespace_name;
行号 TABLESPACE_NAME MAX_TOTAL_G SYSTEM_ALLOCATED_TOTAL_G SYSTEM_ALLOCATED_FREE_G SYSTEM_ALLOCATED_USED_G System_Allocated_Used_% Max_Used_%
1 SYSTEM 16384 0 0.02 0.01 25.11 0
2 ROLL 16384 0 0.09 0.03 26.84 0.0002
3 TEMP 16384 0 0.01 0 0.63 0
4 MAIN 16384 0 0.12 0 0.37 0
5 BOOKSHOP 16384 0 0.15 0 0.6 0
6 DMHR 16415.28 0 0.19 0 0.04 0
6 rows got
select
t.name tablespace_name ,
d.free_size *page/1024/1024 free_space_MB ,
d.total_size *page/1024/1024 total_space_MB,
round((d.total_size-d.free_size)*100.0/d.total_size, 3) “USED_SPACE_PERCENT_%”
from
v$tablespace t,
v$datafile d
where
t.id=d.group_id;
select t.name tablespace_name,d.free_sizeSF_GET_PAGE_SIZE()/1024/1024||‘M’ free_space,
d.total_sizeSF_GET_PAGE_SIZE()/1024/1024||‘M’ total_space,
d.free_size*100/d.total_size “% FREE”
from v$tablespace t, v$datafile d where t.id=d.group_id;