共计 1130 个字符,预计需要花费 3 分钟才能阅读完成。
使用系统 sys 或者 dba 权限的账户创建视图如下:
1. 主要从数据库的表 dba_data_files,dba_segments 两张表中获取。
2. 默认数据库保存的是 byte 单位,转换关系如下:
1024bytes = 1kb
1024KB = 1M
1024M = 1G
CREATE OR REPLACE VIEW V_GET_DISKSPACE AS
SELECT A.TABLESPACE_NAME,
A.USE "USED (MB)",
(B.TOTAL-A.USE) "FREE (MB)",
B.TOTAL "TOTAL (MB)",
round((B.TOTAL-A.USE)/B.TOTAL,5)*100||'%' "PER_FREE"
FROM
(select TABLESPACE_NAME,sum(bytes)/(1024*1024) as USE from dba_segments
/*where tablespace_name NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')*/
GROUP BY TABLESPACE_NAME
) A ,
(WITH TABLESPACE_TOTAL AS
(SELECT tablespace_name,sum(MAXBYTES)/(1024*1024) TOTAL FROM DBA_DATA_FILES T
WHERE /*T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND*/ T.AUTOEXTENSIBLE='YES' group by tablespace_name
UNION ALL
SELECT tablespace_name,sum(bytes) TOTAL FROM DBA_DATA_FILES T
WHERE /*T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND*/ T.AUTOEXTENSIBLE='NO' group by tablespace_name
)
SELECT TABLESPACE_NAME,SUM(TOTAL) TOTAL FROM TABLESPACE_TOTAL GROUP BY TABLESPACE_NAME
) B
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME;
更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-04/130565.htm
正文完
星哥玩云-微信公众号