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

ORACLE数据库、表空间、表的容量相关查询--1

未完待续……未完待续……未完待续……未完待续……

1.查询某个表所占空间大小

col tablespace_name for a15
col segment_name for a15
col segment_type for a15

select segment_name,segment_type,tablespace_name,extents,bytes/1024 KB from dba_segments where segment_name like 'TEST%';

结果如下:

SEGMENT_NAME    SEGMENT_TYPE    TABLESPACE_NAME    EXTENTS         KB
--------------- --------------- --------------- ---------- ----------
TEST            TABLE           USERS                    1         64
TEST1           TABLE           USERS                    1         64
TEST1           TABLE           USERS                  168     794624
TEST5           TABLE           RMANTEST                 1         64
TEST9           TABLE           USERS                  169     800768

3.某个用户下的表所占空间前三位:

select * from (select segment_name,bytes/1024 KB from dba_segments where owner = 'BYS' order by bytes desc ) where rownum <= 3;
SEGMENT_NAME            KB
--------------- ----------
TEST9               800768
TEST1               794624
EMP                     64
用SQL计算出某个用户下所有对象的大小,给出SQL语句和结果。
SQL> show user
User is "bys"
 
SQL> select sum(a.m) from (select segment_name,segment_type,bytes/1024/1024 M from user_segments) a;
 
  SUM(A.M)
----------
         4


2.查询表空间大小及空闲空间大小,使用率等

主要使用的视图有:dba_data_files,dba_free_space

col used_% for a8

select df.tablespace_name,df.sum_df_m as space_m,df.sum_df_m-fs.sum_fs_m as used_m,fs.sum_fs_m as free_space,to_char(trunc((df.sum_df_m-fs.sum_fs_m)/df.sum_df_m,2)*100) as "used_%" from (select tablespace_name,sum(bytes/1024/1024) as sum_df_m from dba_data_files group by tablespace_name) df,(select tablespace_name,sum(bytes/1024/1024) as sum_fs_m from dba_free_space group by tablespace_name) fs where df.tablespace_name=fs.tablespace_name;
结果如下:
TABLESPACE_NAME    SPACE_M     USED_M FREE_SPACE used_%
--------------- ---------- ---------- ---------- --------
SYSAUX                 670    637.125     32.875 95
UN