论坛首页 综合技术论坛

Oracle 查询表空间使用情况

浏览 8248 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-04-02   最后修改:2009-04-02

通过查询dba_free_space表可以了解一个tablespace的空间使用情况。

TABLESPACE_NAME:
    Name of the tablespace containing the extent
FILE_ID:
    ID number of the file containing the extent
BLOCK_ID:
    Starting block number of the extent
BYTES:
    Size of the extent in bytes
BLOCKS:
    Size of the extent in ORACLE block

1。查询表空间的free space

SQL> select
  2      tablespace_name,
  3      count(*) as extends,
  4      round(sum(bytes)/1024/1024, 2) as MB,
  5      sum(blocks) as blocks
  6  from dba_free_space group by tablespace_name;

TABLESPACE    EXTENDS         MB     BLOCKS
---------- ---------- ---------- ----------
UNDOTBS1           16     771.69      49388
SYSAUX             46       8.44        540
BLOBS             375     805.63      51560
USERS             645      67.69       4332
SYSTEM              1       4.75        304
INDX             1871    1071.56      68580
WCAUDIT             1     499.94      31996


2. 查询表空间的总容量

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

TABLESPACE         MB
---------- ----------
SYSAUX            340
UNDOTBS1          805
BLOBS            1000
USERS            6984
SYSTEM            360
WCAUDIT           500
INDX             1500

 

3. 查询表空间使用率

SQL> select
  2      total.tablespace_name,
  3      round(total.MB,2) as Total_MB,
  4      round(total.MB-free.MB, 2) as Used_MB,
  5      round((1-free.MB/total.MB)*100, 2) as Used_Pct
  6  from
  7      (select tablespace_name, sum(bytes)/1024/1024 as MB from dba_free_space group by tablespace_name) free,
  8      (select tablespace_name, sum(bytes)/1024/1024 as MB from dba_data_files group by tablespace_name) total
  9  where
 10      free.tablespace_name=total.tablespace_name;

TABLESPACE   TOTAL_MB    USED_MB   USED_PCT
---------- ---------- ---------- ----------
UNDOTBS1          805      33.31       4.14
SYSAUX            340     331.56      97.52
BLOBS            1000     194.38      19.44
USERS            6984    6916.31      99.03
SYSTEM            360     355.25      98.68
INDX             1500     428.44      28.56
WCAUDIT           500        .06        .01
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics