Categories
Oracle DB

Check ORACLE tablespace size

If you want to check tablespace in Oracle you can do it with these queries:


<SQL> SELECT 
    u.TABLESPACE_NAME,
    CAST(USED_PERCENT AS INTEGER) "Used %",
    (BYTES /1024 / 1024) "Size (MB)",
    FILE_NAME
  FROM 
    DBA_TABLESPACE_USAGE_METRICS u,DBA_DATA_FILES f
  WHERE 
    u.TABLESPACE_NAME = f.TABLESPACE_NAME
  ORDER BY 
    u.TABLESPACE_NAME;

Or the second query:

<SQL> SELECT
   X.TABLESPACE_NAME AS "Tablespace",
   X.FILE_NAME AS "Path",
   ROUND(x.bytes/(1024*1024),2) AS "Size (MB)",
   ROUND(Y.USED_SPACE*Z.BLOCK_SIZE/(1024*1024),2) AS "Used (MB)",
   Round(((Y.USED_SPACE*Z.BLOCK_SIZE/(1024*1024)) / (x.bytes/(1024*1024))) * 100,2) AS "Used in %"
 FROM
   DBA_DATA_FILES X,
   DBA_TABLESPACE_USAGE_METRICS Y,
   DBA_TABLESPACES Z
 WHERE
       X.TABLESPACE_NAME = Y.TABLESPACE_NAME
   AND X.TABLESPACE_NAME = Z.TABLESPACE_NAME         
 ORDER BY
   5 DESC;

If you want to increase the table space you can do it with:

<SQL> ALTER DATABASE DATAFILE 'path to tablefile' RESIZE 1500M;