日期:2014-05-16  浏览次数:20410 次

查看所有表空间大小
1. 查看所有表空间大小

SQL> select tablespace_name,sum(bytes)/1024/1024 from dba_data_files
  2  group by tablespace_name;

2. 已经使用的表空间大小
SQL> select tablespace_name,sum(bytes)/1024/1024 from dba_free_space
  2  group by tablespace_name;

3. 所以使用空间可以这样计算

select a.tablespace_name,total,free,total-free used from 
( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files
   group by tablespace_name) a, 
( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space
   group by tablespace_name) b
where a.tablespace_name=b.tablespace_name;


4. 下面这条语句查看所有segment的大小。
Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name

5. 还有在命令行情况下如何将结果放到一个文件里。
SQL> spool out.txt
SQL> select * from v$database;
SQL> spool off
error:
IMP-00003: ORACLE error 1536 encountered ORA-01536: space quota exceeded for tablespace 'USERS'
表空间的配额用完了。
去掉配额限制:
alter user 用户名 quota unlimited on users;

查询表空间使用情况的脚本

?

select df.tablespace_name "Tablespace",

totalusedspace "Used MB",

(df.totalspace - tu.totalusedspace) "Free MB",

df.totalspace "Total MB",

round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))

"Pct. Free"

from

(select tablespace_name,

round(sum(bytes) / 1048576) TotalSpace

from dba_data_files