Oracle Tablespace

Oracle Tablespace

The following are statements and queries I use working with tablespaces in Oracle.

Query Tablespace Usage

⚠️ Please be aware of the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
set tab off
set linesize 200
set pagesize 100
select
files.tablespace_name,
maxbytes as "BYTES SIZE",
bytes - free_bytes as "BYTES USED",
maxbytes - (bytes - free_bytes) as "BYTES AVAIL",
round(maxbytes / 1048576, 2) as "MB SIZE",
round((bytes - free_bytes) / 1048576, 2)  as "MB USED",
round((maxbytes - (bytes - free_bytes)) / 1048576, 2) as "MB AVAIL",
round(((bytes - free_bytes) / maxbytes) * 100, 2) as "% USED",
round((100 - ((bytes - free_bytes) / maxbytes) * 100), 2) as "% FREE"
from
  (select tablespace_name, sum(bytes) as bytes, sum(maxbytes) as maxbytes from
    (select tablespace_name, bytes, case autoextensible when 'YES' then maxbytes else bytes end as maxbytes from dba_data_files) group by tablespace_name) files,
  (select tablespace_name, sum(bytes) as free_bytes from dba_free_space group by tablespace_name) free
where files.tablespace_name = free.tablespace_name
order by 9;
order by free.tablespace_name;

Example Query Output

1
2
3
4
5
6
7
TABLESPACE_NAME                BYTES SIZE BYTES USED BYTES AVAIL    MB SIZE    MB USED   MB AVAIL     % USED     % FREE
------------------------------ ---------- ---------- ----------- ---------- ---------- ---------- ---------- ----------
TABLESPACE1                    5.7767E+11 5.3518E+11  4.2491E+10  550911.83  510389.33    40522.5      92.64       7.36
TABLESPACE2                    1.8511E+12 1.6840E+12  1.6713E+11 1765375.22 1605991.81  159383.41      90.97       9.03
TABLESPACE3                    3.4360E+10 2.4939E+10  9420783616   32767.98   23783.63    8984.36      72.58      27.42
TABLESPACE4                    1.0308E+11 6.4627E+10  3.8452E+10   98303.95   61633.55   36670.41       62.7       37.3
TABLESPACE5                    3.4360E+10 2.0243E+10  1.4116E+10   32767.98   19305.56   13462.42      58.92      41.08