一、普通查询
SELECT Total.name TablespaceName,
Free_space,
(total_space - Free_space) Used_space,
total_space
FROM (select tablespace_name, sum(bytes / 1024 / 1024) Free_Space
from sys.dba_free_space
group by tablespace_name) Free,
(select b.name, sum(bytes / 1024 / 1024) TOTAL_SPACE
from sys.v_$datafile a, sys.v_$tablespace B
where a.ts# = b.ts#
group by b.name) Total
WHERE Free.Tablespace_name = Total.name;
二、根据Oracle 不活动连接用户查询使用空间
select t.owner 名称,sum(t.BYTES)/1024/1024/1024 使用大小_G from dba_segments t
where t.TABLESPACE_NAME=‘USERS‘ and t.owner not in(
select DISTINCT z.USERNAME from (
select t.USERNAME,DECODE(t.STATUS,‘INACTIVE‘,‘等待操作‘,‘ACTIVE‘,‘执行状态‘,‘KILLED‘,‘标注-KILL‘) 状态,
t.SCHEMA#,t.SCHEMANAME,t.MACHINE 机器名 from v$Session t where t.SCHEMANAME<>‘SYS‘ and t.SCHEMA#<>0
) z )
group by t.owner order by t.owner,sum(t.BYTES)/1024/1024/1024